#include "BestQuoteFilter.h"

#include <bondlib/BondContainer.h>
#include <bondlib/BondDict.h>
#include <bondlib/BondType.h>
#include <bondlib/Pinyin.h>
#include <bondlib/QBCategoryFlagInfo.h>
#include <bondlib/QBIssuerInfo.h>
#include <bondlib/QBProviceInfo.h>
#include <bondlib/QBSwSectorInfo.h>
#include <core/ImageMgr.h>
#include <core/StyleMgr.h>
#include <core/comdefs.h>
#include <core/strings/string_util.h>
#include <widgets/KeySearchWidget.h>
#include <widgets/SButtonShowAll.h>
#include <widgets/SCalendar.h>
#include <widgets/SCheckEx.h>
#include <widgets/SFilterButton.h>
#include <widgets/SFilterTree.h>
#include <widgets/SImageButton.h>
#include <widgets/SLineEdit.h>
#include <widgets/STabCtrl.h>
#include <widgets/STips.h>
#include <widgets/STreeComboWidget.h>

#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
#include <QStylePainter>
#include <QTimer>
#include <QVBoxLayout>
#include <algorithm>

#include "../../BondSearch.h"
#include "../../IssuerSearch.h"
#include "../../StringResource.h"

using namespace qb::base;

namespace {
enum childid {
  id_chk_valid = 1001,
  id_chk_bothvalid,
  id_chk_bidvalid,
  id_chk_ofrvalid,
};
const int lineHeight = 24;
const int editWidth = 48;
const int gap = 4;
const int labelWidth = 82;

const QString labelStyle =
    QString(
        "QLabel "
        "{background-color:#%1;color:#%2;border:none;border-radius:2px;}")
        .arg(NAME_COLOR("StaticTextBK").rgb(), 0, 16)
        .arg(NAME_COLOR("TitleWord").rgb(), 0, 16);

const QString labelStyle2 =
    QString("QLabel {color:#%1;border:none;border-radius:2px;}")
        .arg(NAME_COLOR("TitleWord").rgb(), 0, 16);
}  // namespace

class BondFilterIssuerSearchEngine : public IssuerSearchEngine {
 public:
  BondFilterIssuerSearchEngine() { m_userdata = issuerNormal; }
  void setFilterWnd(BestQuoteFilter* filter) { m_filter = filter; }
  virtual void onResultSelected(const QString& key) override {
    QB_CHECK_RETURN_VOID1(m_filter);
    int index = key.toLatin1().toInt();
    const IssuerInfo* pInfo =
        CQBIssuerInfo::instance().GetIssuerInfoByIndex(index);
    if (pInfo && m_filter) {
      m_filter->setIssuerSearchResult(pInfo);
    }
  }

 private:
  BestQuoteFilter* m_filter;
};

class BondFilterGuarantorSearchEngine : public IssuerSearchEngine {
 public:
  BondFilterGuarantorSearchEngine() { m_userdata = issuerGuarantor; }
  void setFilterWnd(BestQuoteFilter* filter) { m_filter = filter; }
  virtual void onResultSelected(const QString& key) override {
    QB_CHECK_RETURN_VOID1(m_filter);
    int index = key.toLatin1().toInt();
    const IssuerInfo* pInfo =
        CQBIssuerInfo::GuarantorInstitution().GetIssuerInfoByIndex(index);
    if (pInfo && m_filter) {
      m_filter->setGuarantorSearchResult(pInfo);
    }
  }

 private:
  BestQuoteFilter* m_filter;
};

FilterTableView::FilterTableView(QWidget* parent) : QWidget(parent) {
  setWindowFlags(Qt::ToolTip | Qt::BypassGraphicsProxyWidget |
                 Qt::FramelessWindowHint);
  setFixedWidth(180);
  setFixedHeight(180);
  setContentsMargins(0, 0, 0, 0);
  setStyleSheet(
      QString(
          "background-color: #%1;border: 1px solid #%2; border-radius: 2px;")
          .arg(StyleMgr::instance().color("BackNormal").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  installEventFilter(this);

  m_tableView = new QTableView(this);
  m_model = new QStandardItemModel(0, 2, this);

  m_tableView->setModel(m_model);
  m_tableView->setFrameShape(QFrame::NoFrame);
  m_tableView->setShowGrid(false);
  m_tableView->setFocusPolicy(Qt::NoFocus);
  m_tableView->horizontalHeader()->setVisible(false);
  m_tableView->verticalHeader()->setVisible(false);
  m_tableView->setColumnWidth(0, 100);
  m_tableView->setColumnWidth(1, 24);
  m_tableView->setSelectionMode(QAbstractItemView::NoSelection);
  m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
  m_tableView->setStyleSheet(
      QString("QTableView {background-color: #%1; color: #%2; border: none;}")
          .arg(StyleMgr::instance().color("BackNormal").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("TextNormal").rgb(), 0, 16));

  // Adding sample data
  for (int i = 0; i < (int)m_vctContent.size(); ++i) {
    QList<QStandardItem*> items;
    QStandardItem* item = new QStandardItem(m_vctContent[i]);
    items.append(item);

    SImageButton* buttonRemove = new SImageButton(this, "widgets_action_clean");
    m_model->appendRow(items);
    m_tableView->setIndexWidget(m_model->index(i, 1), buttonRemove);

    connect(buttonRemove, &SImageButton::clicked, [=]() {
      int row = m_model->indexFromItem(items.first()).row();
      m_model->removeRow(row);

      int rcount = m_model->rowCount();
      if (rcount < 5 && rcount > 0) {
        setFixedSize(m_tableWidth + 50, rcount * 32 + 20);
      } else if (rcount >= 5) {
        setFixedSize(m_tableWidth + 60, 172);
      }

      emit filterRemove(row);
    });
  }

  QVBoxLayout* mainLayout = new QVBoxLayout(this);
  mainLayout->addWidget(m_tableView);
  setLayout(mainLayout);
}

void FilterTableView::setContent(const std::vector<QString>& vctContent) {
  QPainter painter(this);
  QFontMetrics metrics(painter.font());

  m_vctContent = vctContent;
  int count = (int)m_vctContent.size();
  for (int i = 0; i < count; ++i) {
    m_tableWidth = max(metrics.width(m_vctContent[i]) + 8, m_tableWidth);
  }

  if (m_tableWidth > 0) {
    if (count < 5) {
      setFixedSize(m_tableWidth + 50, count * 32 + 20);
    } else {
      setFixedSize(m_tableWidth + 60, 172);
    }

    m_tableView->setColumnWidth(0, m_tableWidth);

    m_model->removeRows(0, m_model->rowCount());
    for (int i = 0; i < count; ++i) {
      QList<QStandardItem*> items;
      QStandardItem* item = new QStandardItem(m_vctContent[i]);
      items.append(item);

      SImageButton* button = new SImageButton(this, "widgets_action_clean");
      m_model->appendRow(items);
      m_tableView->setIndexWidget(m_model->index(i, 1), button);

      connect(button, &SImageButton::clicked, [=]() {
        int row = m_model->indexFromItem(items.first()).row();
        m_model->removeRow(row);

        int rcount = m_model->rowCount();
        if (rcount < 5 && rcount > 0) {
          setFixedSize(m_tableWidth + 50, rcount * 32 + 20);
        } else if (rcount >= 5) {
          setFixedSize(m_tableWidth + 60, 172);
        }

        emit filterRemove(row);
      });
    }
  }
}

bool FilterTableView::eventFilter(QObject* watched, QEvent* event) {
  if (!isVisible()) return false;

  switch (event->type()) {
    case QEvent::Hide:
    case QEvent::WindowDeactivate: {
      hide();
    } break;
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseButtonDblClick: {
      QMouseEvent* me = dynamic_cast<QMouseEvent*>(event);
      QPoint pt = me->globalPos();
      pt = mapFromGlobal(pt);
      if (!rect().contains(pt)) {
        hide();
      }
    } break;
    default:
      break;
  }

  return false;
}

BestQuoteFilter::BestQuoteFilter(QWidget* parent)
    : QFrame(parent), m_rect(0, 0, 0, 0) {
  m_hasRatingRightsOfCDC = true;  // AfxGetUserAccountManager().HasAuthOfCDC();
  m_hasRatingRightsOfCSI = true;  // AfxGetUserAccountManager().HasAuthOfCSI();
  m_hasRatingRightsOfCBR = true;  // AfxGetUserAccountManager().HasAuthOfCBR();

  m_filterCondition.stBlh.nMatFlg = 1;
  m_filterCondition.stBlh.nHasFlg = 1;

  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  setupUi();
  resetControl();
  setMouseTracking(true);
}

BestQuoteFilter::~BestQuoteFilter() {}

namespace {
#define _setTabSelect(tab, member, typeAll, typeNone)            \
  for (int i = 0; i < sizeof(stBlh.member) / sizeof(int); i++) { \
    if (stBlh.member[i] == typeNone)                             \
      break;                                                     \
    else {                                                       \
      if (i != 0)                                                \
        tab->selectTab(stBlh.member[i] - typeAll, true);         \
      else                                                       \
        tab->selectTab(stBlh.member[i] - typeAll);               \
    }                                                            \
  }

#define _setLiquidityTabSelect(tab, member) \
  {                                         \
    int sz = sizeof(stBlh.member);          \
    const char* p = stBlh.member;           \
    int n = 0;                              \
    do {                                    \
      switch (*p) {                         \
        case '\0': {                        \
          if (n == 0) tab->selectTab(0);    \
        } break;                            \
        case 'S':                           \
          tab->selectTab(1, true);          \
          break;                            \
        case 'A':                           \
          tab->selectTab(2, true);          \
          break;                            \
        case 'B':                           \
          tab->selectTab(3, true);          \
          break;                            \
        case 'C':                           \
          tab->selectTab(4, true);          \
          break;                            \
        case 'D':                           \
          tab->selectTab(5, true);          \
          break;                            \
        default:                            \
          break;                            \
      }                                     \
      p++;                                  \
      n++;                                  \
    } while (*p != '\0' && n < sz);         \
  }
}  // namespace

void BestQuoteFilter::resetControl() {
  m_chkValid->setSelectState(Qt::Checked);
  m_chkBothValid->setSelectState(Qt::Unchecked);
  m_chkBidValid->setSelectState(Qt::Unchecked);
  m_chkOfrValid->setSelectState(Qt::Unchecked);

  m_rdoYield->setSelectState(Qt::Checked);
  m_rdoPrice->setSelectState(Qt::Unchecked);
  onRadioStateChanged(0);

  // m_edtSearch->setText("");//搜索

  m_edtBid->setText("");  // bid
  m_edtBid2->setText("");
  m_edtOfr->setText("");  // ofr
  m_edtOfr2->setText("");
  m_edtBidCdc->setText("");  // bid-cdc
  m_edtBidCdc2->setText("");
  m_edtCdcOfr->setText("");  // cdc-ofr
  m_edtCdcOfr2->setText("");
  m_edtBidOfr->setText("");  // bid-ofr
  m_edtBidOfr2->setText("");
  m_edtCouponRate->setText("");  // couponrate
  m_edtCouponRate2->setText("");
  m_edtCdcValue->setText("");  // cdc
  m_edtCdcValue2->setText("");
  m_edtVolBid->setText("");  // vol.bid
  m_edtVolOfr->setText("");  // vol.ofr
  m_edtTermBegin->setText("");
  m_edtTermEnd->setText("");

  m_tabProduct1->selectTab(0);  // 产品
  //	m_tabProduct2->selectTab(0);//政金债
  m_tabLocalBond->selectTab(0);      // 地方债
  m_tabLocalBondArea->selectTab(0);  // 地方债地区
  m_tabHot1->selectTab(0);           // 热门概念
  //	m_tabCommon->selectTab(0);//常用
  m_tabSettlement->selectTab(0);          // 清算速度
  m_tabQuoteType->selectTab(0);           // 报价类型
  m_tabETSBond->selectTab(0);             // 永续债
  m_tabSubordinatedBond->selectTab(0);    // 次级债
  m_tabListedVenues->selectTab(0);        // 上市场所
  m_tabRateType->selectTab(0);            // 利率方式
  m_tabCorp->selectTab(0);                // 企业
  m_tabInvest->selectTab(0);              // 城投
  m_tabPformType->selectTab(0);           // 平台债
  m_tabIssuerRating->selectTab(0);        // 主体
  m_tabBondRating->selectTab(0);          // 债项
  m_tabCDCRating->selectTab(0);           // 中债隐含
  m_tabCSIRating->selectTab(0);           // 中证隐含
  m_tabCBRRating->selectTab(0);           // 中债资信
  m_tabOutlook->selectTab(0);             // 展望
  m_tabBondAssure->selectTab(0);          // 担保
  m_tabThirdPartGuarantee->selectTab(0);  // 三方担保
  m_tabBondNCD->selectTab(0);             // NCD
  m_tabAssetStatus->selectTab(0);         // 发行方式
  m_tabCouponType->selectTab(0);          // 票面
  m_tabOptionType->selectTab(0);          // 含权
  m_tabBondLiquidity->selectTab(0);       // 债券流动性
  m_tabIssuerLiquidity->selectTab(0);     // 主体流动性
  m_tabGrade->selectTab(0);               // 高收益债
  m_tabYear->selectTab(0);                // 发行年份
  m_tabPrincipayPayType->selectTab(0);    // 偿还方式
  m_fltTerm->selectTab(0);                // 期限

  m_treeLocalBondSpecial->clearSelect();
  m_treeLocalBondArea->clearSelect();
  m_treeNCD->clearSelect();
  m_treeMuniArea->clearSelect();
  m_treeIssuerRating->clearSelect();
  m_treeCBRRating->clearSelect();
  m_treeBondRating->clearSelect();
  m_treeCDCRating->clearSelect();
  m_treeCSIRating->clearSelect();
  m_treeSubType->clearSelect();
  m_treeSector->clearSelect();
  m_treeArea->clearSelect();
  m_treeYear->clearSelect();
}

void BestQuoteFilter::setBLH(const BLHCONDITION& stBlh) {
  m_rdoYield->setSelectState(stBlh.nYieldOrPrice == 0 ? Qt::Checked
                                                      : Qt::Unchecked);
  m_rdoPrice->setSelectState(stBlh.nYieldOrPrice == 1 ? Qt::Checked
                                                      : Qt::Unchecked);

  m_chkValid->setSelectState(stBlh.nValid == 1 ? Qt::Checked : Qt::Unchecked);
  m_chkBothValid->setSelectState(stBlh.nBothFlg == 1 ? Qt::Checked
                                                     : Qt::Unchecked);
  m_chkBidValid->setSelectState(stBlh.nBidValid == 1 ? Qt::Checked
                                                     : Qt::Unchecked);
  m_chkOfrValid->setSelectState(stBlh.nOfrValid == 1 ? Qt::Checked
                                                     : Qt::Unchecked);

  m_edtBid->setText("");  // bid
  m_edtBid2->setText("");
  m_edtOfr->setText("");  // ofr
  m_edtOfr2->setText("");
  m_edtBidCdc->setText("");  // bid-cdc
  m_edtBidCdc2->setText("");
  m_edtCdcOfr->setText("");  // cdc-ofr
  m_edtCdcOfr2->setText("");
  m_edtBidOfr->setText("");  // bid-ofr
  m_edtBidOfr2->setText("");
  m_edtCouponRate->setText("");  // couponrate
  m_edtCouponRate2->setText("");
  m_edtCdcValue->setText("");  // cdc
  m_edtCdcValue2->setText("");
  m_edtVolBid->setText("");  // vol.bid
  m_edtVolOfr->setText("");  // vol.ofr
  m_edtTermBegin->setText("");
  m_edtTermEnd->setText("");

  // 产品
  _setTabSelect(m_tabProduct1, nTypeNew, CBondContainer::newBondAll,
                CBondContainer::newBondNone);
  // 政金债
  _setTabSelect(m_tabProduct2, nFinDebt, CBondContainer::FinDebtAll,
                CBondContainer::FinDebtNone);
  // 地方债
  _setTabSelect(m_tabLocalBond, nLocalBond, CBondContainer::LocalBondAll,
                CBondContainer::LocalBondNone);
  // 常用
  //	_setTabSelect(m_tabCommon, nCommonUse, CBondContainer::CommAll,
  // CBondContainer::CommNone); 清算速度
  _setTabSelect(m_tabSettlement, nSettlement, CBondContainer::StmAll,
                CBondContainer::StmNone);
  // 报价类型
  _setTabSelect(m_tabQuoteType, nQuoteType, CBondContainer::StmAll,
                CBondContainer::StmNone);
  // 永续债
  _setTabSelect(m_tabETSBond, nETSBond, CBondContainer::ETSBondAll,
                CBondContainer::ETSBondNone);
  // 企业
  _setTabSelect(m_tabCorp, nInstion, CBondContainer::InstAll,
                CBondContainer::InstNone);
  // 城投
  _setTabSelect(m_tabInvest, nMunicp, CBondContainer::MunicNone,
                CBondContainer::MunicAll);
  // 平台债
  _setTabSelect(m_tabPformType, nPlatform, CBondContainer::PlatforamAll,
                CBondContainer::PlatforamNone);
  // 主体
  _setTabSelect(m_tabIssuerRating, nIssuerRating, CBondContainer::RatingAll,
                CBondContainer::RatingNone);
  // 债项
  _setTabSelect(m_tabBondRating, nDebtRating, CBondContainer::DRatingAll,
                CBondContainer::DRatingNone);
  // 中债隐含
  if (m_hasRatingRightsOfCDC) {
    _setTabSelect(m_tabCDCRating, nCDCRating, CBondContainer::CDCRatingAll,
                  CBondContainer::CDCRatingNone);
  } else
    m_tabCDCRating->selectTab(0);
  // 中证隐含
  if (m_hasRatingRightsOfCSI) {
    _setTabSelect(m_tabCSIRating, nCSIRating, CBondContainer::CSIRatingAll,
                  CBondContainer::CSIRatingNone);
  } else
    m_tabCSIRating->selectTab(0);

  // 展望
  _setTabSelect(m_tabOutlook, nOutlookRating, CBondContainer::OutlookRatingAll,
                CBondContainer::OutlookRatingNone);
  // 担保
  _setTabSelect(m_tabBondAssure, nWarrant, CBondContainer::WarrAll,
                CBondContainer::WarrNone);
  // NCD
  _setTabSelect(m_tabBondNCD, nNCDRating, CBondContainer::NCDRatingAll,
                CBondContainer::NCDRatingNone);
  // 发行方式
  _setTabSelect(m_tabAssetStatus, nAssetStatus, CBondContainer::AssetAll,
                CBondContainer::AssetNone);
  // 票面
  //	_setTabSelect(m_tabCouponType, nCouponType, CBondContainer::CouponAll,
  // CBondContainer::CouponNon); 含权
  _setTabSelect(m_tabOptionType, nRightEx, CBondContainer::RightExAll,
                CBondContainer::RightExNone);
  //	//债券流动性
  _setLiquidityTabSelect(m_tabBondLiquidity, sBondLiquidity);
  //	//主体流动性
  _setLiquidityTabSelect(m_tabIssuerLiquidity, sIssuerLiquidity);
  // 	//高收益债
  _setTabSelect(m_tabGrade, nHighYieldBond, CBondContainer::HYBAll,
                CBondContainer::HYBNone);
  // 偿还方式
  _setTabSelect(m_tabPrincipayPayType, nPrincipalPayType,
                CBondContainer::PPTAll, CBondContainer::PPTNone);

  // 	//旧方案-行业
  // 	memset(m_szSectorOld, 0, sizeof(m_szSectorOld));
  // 	memcpy(m_szSectorOld, stBlh.szSector, sizeof(stBlh.szSector));
  //
  // 	AssertWnd(m_pCouponRate)m_pCouponRate->SetWindowText(_T(""));
  // //票面利率
  // 	AssertWnd(m_pCouponRateEnd)m_pCouponRateEnd->SetWindowText(_T(""));
  // 	AssertWnd(m_pCdcValue)m_pCdcValue->SetWindowText(_T(""));
  // //中债估值
  // AssertWnd(m_pCdcValueEnd)m_pCdcValueEnd->SetWindowText(_T(""));
  //
  // 	//发行人
  // 	for (int i = 0; i < sizeof(stBlh.szIssuer) / sizeof(IssuerChar); i++)
  // 	{
  // 		Issuer stUnit;
  // 		if (strcmp(stBlh.szIssuer[i], "") != 0)
  // 		{
  // 			const IssuerInfo* pIssuer =
  // AfxGetIssuerInfo().GetIssuerInfo(std::string(stBlh.szIssuer[i]));
  // if (pIssuer)
  // 			{
  // 				stUnit.szCode.append(pIssuer->field((int)kIssuerInfo::Institution_Code));
  // 				if (m_isEnglish)
  // 					stUnit.szName.append(pIssuer->field((int)kIssuerInfo::Full_Name_E));
  // 				else
  // 					stUnit.szName.append(pIssuer->field((int)kIssuerInfo::Full_Name_C));
  // 				m_stlIssuer.push_back(stUnit);
  // 			}
  // 		}
  // 	}
  //
  // 	if (!IsWindow(m_cpIssuerList.GetSafeHwnd()))
  // 		CreateIssuerList();
  // 	m_cpIssuerList.SetIssuer(&m_stlIssuer, false);
  //
  // 	//担保人
  // 	if (m_nFilterType == FilterWnd::kFT_Broker)
  // 	{
  // 		for (int i = 0; i < sizeof(stBlh.szGuarantor) /
  // sizeof(IssuerChar); i++)
  // 		{
  // 			Issuer stUnit;
  // 			if (strcmp(stBlh.szGuarantor[i], "") != 0)
  // 			{
  // 				const IssuerInfo* pIssuer =
  // AfxGetIssuerInfo().GetIssuerInfo(std::string(stBlh.szGuarantor[i]));
  // if (pIssuer)
  // 				{
  // 					stUnit.szCode.append(pIssuer->field((int)kIssuerInfo::Institution_Code));
  // 					if (m_isEnglish)
  // 						stUnit.szName.append(pIssuer->field((int)kIssuerInfo::Full_Name_E));
  // 					else
  // 						stUnit.szName.append(pIssuer->field((int)kIssuerInfo::Full_Name_C));
  // 					m_stlGuarantor.push_back(stUnit);
  // 				}
  // 			}
  // 		}
  // 		if (!IsWindow(m_cpGuarantorList.GetSafeHwnd()))
  // 			CreateGuarantorList();
  // 		m_cpGuarantorList.SetIssuer(&m_stlGuarantor, false);
  // 	}
  //
  // 	//行业
  // 	ClearListValue(&m_stIndustryData.stlIndustry);
  // 	for (int i = 0; i < sizeof(stBlh.szSector2021) / sizeof(SectorChar);
  // i++)
  // 	{
  // 		Issuer stUnit;
  // 		if (strcmp(stBlh.szSector2021[i], "") != 0)
  // 		{
  // 			const QBSWSECTORINFO* pSector =
  // AfxGetSwSectorInfo2021().GetSwSectorInfo(std::string(stBlh.szSector2021[i]));
  // 			if (pSector)
  // 			{
  // 				stUnit.szCode.append(pSector->SW_Internal_Code);
  // 				if (m_isEnglish)
  // 					stUnit.szName.append(pSector->SW_English_Name);
  // 				else
  // 					stUnit.szName.append(pSector->SW_Name);
  // 				m_stlIndustry.push_back(stUnit);
  // 			}
  // 		}
  // 	}
  // 	if (!IsWindow(m_cpIndustryList.GetSafeHwnd()))
  // 		CreateIndustryList();
  // 	m_cpIndustryList.SetData(&m_stIndustryData, &m_stlIndustry, false);
  // 	ConditionChange(m_stlIndustry, m_pComIndustry);
  //
  // 	//债券子类别
  // 	ClearListValue(&m_stSubBondData.stlSubBond);
  // 	for (int i = 0; i < sizeof(stBlh.szSubType) / sizeof(SubTypeChar); i++)
  // 	{
  // 		Issuer stUnit;
  // 		if (strcmp(stBlh.szSubType[i], "") != 0)
  // 		{
  // 			const CBondType* pSubType =
  // AfxGetBondType().GetBondSubType(stBlh.szSubType[i]); if (pSubType)
  // 			{
  // 				stUnit.szCode.append(pSubType->m_Code.c_str());
  // 				stUnit.szName.append(pSubType->m_Name_C.c_str());
  // 				m_stlSubBond.push_back(stUnit);
  // 			}
  // 		}
  // 	}
  // 	if (!IsWindow(m_cpSubBondList.GetSafeHwnd()))
  // 		CreateSubBondList();
  // 	m_cpSubBondList.SetData(&m_stSubBondData, &m_stlSubBond, false);
  // 	ConditionChange(m_stlSubBond, m_pComSubBond);
  //
  // 	//地区
  // 	ClearListValue(&m_stlAreaData);
  // 	for (int i = 0; i < sizeof(stBlh.szArea) / sizeof(AreaChar); i++)
  // 	{
  // 		Issuer stUnit;
  // 		if (strcmp(stBlh.szArea[i], "") != 0)
  // 		{
  // 			const QBPROVINCEINFO* pArea =
  // AfxGetProvinceInfo().GetProviceInfo(std::string(stBlh.szArea[i]));
  // if (pArea)
  // 			{
  // 				stUnit.szCode.append(pArea->Area_Code);
  // 				if (m_isEnglish)
  // 					stUnit.szName.append(pArea->Area_English_Name);
  // 				else
  // 					stUnit.szName.append(pArea->Area_Name);
  // 				m_stlArea.push_back(stUnit);
  // 			}
  // 		}
  // 	}
  // 	if (!IsWindow(m_cpAreaList.GetSafeHwnd()))
  // 		CreateAreaList();
  // 	m_cpAreaList.SetData(&m_stlAreaData, &m_stlArea);
  // 	ConditionChange(m_stlArea, m_pComArea);
  //
  //
  //
  // 	//发行年份
  // 	ClearListValue(&m_stlYearData);
  // 	for (int i = 0; i < sizeof(stBlh.nIssueYear) / sizeof(UINT); i++)
  // 	{
  // 		Issuer stUnit;
  // 		int nYear = stBlh.nIssueYear[i];
  // 		if (nYear > 0 && nYear < 10000)
  // 		{
  // 			char szyear[10] = { 0 };
  // 			FMTBUF(szyear, "%d", nYear);
  // 			stUnit.szName.append(szyear);
  // 			m_stlYear.push_back(stUnit);
  // 		}
  // 	}
  // 	if (!IsWindow(m_cpYearList.GetSafeHwnd()))
  // 		CreateYearList();
  // 	m_cpYearList.SetData(&m_stlYearData, &m_stlYear);
  // 	ConditionChange(m_stlYear, m_pComYear);

  // 	//期限
  // 	m_bCommonDeadline = true;
  // 	m_bShowDY = true;
  // 	m_bDeadlineHover = false;
  // 	m_pDateBegin->SetWindowText(_T(""));
  // 	m_pDateEnd->SetWindowText(_T(""));
  // 	if (stBlh.nRange[0] == CBondContainer::RangeAll)
  // 	{
  // 		m_tabDeadLine->SetTabSelect(0);
  // 	}
  // 	else if (stBlh.nRange[0] == CBondContainer::RangeOther ||
  // stBlh.nRange[0] == CBondContainer::RangeDate)
  // 	{
  // 		m_tabDeadLine->SetTabSelect(-1);
  // 		if (stBlh.nRange[0] == CBondContainer::RangeOther)
  // 		{
  // 			m_bShowDY = true;
  // 			m_bDeadlineHover = false;
  // 			m_bCommonDeadline = false;
  // 		}
  // 		else
  // 		{
  // 			m_bShowDY = false;
  // 			m_bDeadlineHover = true;
  // 			m_bCommonDeadline = false;
  // 		}
  // 		m_pDateBegin->SetWindowText(SSA2W(stBlh.sDate1));
  // 		m_pDateEnd->SetWindowText(SSA2W(stBlh.sDate2));
  // 	}
  // 	else if (stBlh.nRange[0] != CBondContainer::RangeOther &&
  // stBlh.nRange[0] != CBondContainer::RangeDate)
  // 	{
  // 		for (int i = 0; i < sizeof(stBlh.nRange) / sizeof(int); i++)
  // 		{
  // 			if (stBlh.nRange[i] == CBondContainer::RangeNone)
  // 				break;
  // 			else
  // 			{
  // 				if (i !=
  // 0)m_tabDeadLine->SetTabSelect(stBlh.nRange[i] - CBondContainer::RangeAll,
  // true); 				else
  // m_tabDeadLine->SetTabSelect(stBlh.nRange[i] - CBondContainer::RangeAll);
  // 			}
  // 		}
  // 	}
  //	CommonTransferAdvan(m_bCommonDeadline);
}

namespace {
#define _getTabSelect(tab, member, type)            \
  tab->getSelTab(vctSelect);                        \
  for (int i = 0; i < (int)vctSelect.size(); i++) { \
    int nSelect = vctSelect[i];                     \
    stBlh.member[i] = type + nSelect;               \
  }
}  // namespace

void BestQuoteFilter::getBLH(BLHCONDITION& stBlh) {
  stBlh.nMatFlg = 1;
  stBlh.nHasFlg = m_chkValid->isSelected();       // 有效报价
  stBlh.nBothFlg = m_chkBothValid->isSelected();  // 双边
  stBlh.nBidValid = m_chkBidValid->isSelected();  // bid
  stBlh.nOfrValid = m_chkOfrValid->isSelected();  // ofr
  stBlh.nYieldOrPrice = m_rdoPrice->isSelected();

  std::vector<int> vctSelect;
  // 清算速度
  _getTabSelect(m_tabSettlement, nSettlement, CBondContainer::StmAll);
  // 报价类型
  _getTabSelect(m_tabQuoteType, nQuotePriceType, CBondContainer::QptAll);

  QString strTemp;
  // bid
  strTemp = m_edtBid->text();
  FIELDCOPY(stBlh.sBPrice, strTemp.toLatin1().data());
  strTemp = m_edtBid2->text();
  FIELDCOPY(stBlh.sBPriceEnd, strTemp.toLatin1().data());

  // ofr
  strTemp = m_edtOfr->text();
  FIELDCOPY(stBlh.sOPrice, strTemp.toLatin1().data());
  strTemp = m_edtOfr2->text();
  FIELDCOPY(stBlh.sOPriceEnd, strTemp.toLatin1().data());

  // bid-中债
  strTemp = m_edtBidCdc->text();
  FIELDCOPY(stBlh.sBidCdc, strTemp.toLatin1().data());
  strTemp = m_edtBidCdc2->text();
  FIELDCOPY(stBlh.sBidCdcEnd, strTemp.toLatin1().data());

  // 中债-ofr
  strTemp = m_edtCdcOfr->text();
  FIELDCOPY(stBlh.sCdcOfr, strTemp.toLatin1().data());
  strTemp = m_edtCdcOfr2->text();
  FIELDCOPY(stBlh.sCdcOfrEnd, strTemp.toLatin1().data());

  // Bid.Vol
  // stBlh.nVolBpcCnd = (m_bVolBidComLess == true ? 0 : 1);
  strTemp = m_edtVolBid->text();
  FIELDCOPY(stBlh.sVolBid, strTemp.toLatin1().data());

  // Ofr.Vol
  // stBlh.nVolOpcCnd = (m_bVolOfrComLess == true ? 0 : 1);
  strTemp = m_edtVolOfr->text();
  FIELDCOPY(stBlh.sVolOfr, strTemp.toLatin1().data());

  // bid-ofr
  strTemp = m_edtBidOfr->text();
  FIELDCOPY(stBlh.sBidOfr, strTemp.toLatin1().data());
  strTemp = m_edtBidOfr2->text();
  FIELDCOPY(stBlh.sBidOfrEnd, strTemp.toLatin1().data());

  // 票面利率
  strTemp = m_edtCouponRate->text();
  FIELDCOPY(stBlh.sCouponRate, strTemp.toLatin1().data());
  strTemp = m_edtCouponRate2->text();
  FIELDCOPY(stBlh.sCouponRateEnd, strTemp.toLatin1().data());

  // 中债估值
  strTemp = m_edtCdcValue->text();
  FIELDCOPY(stBlh.sCdcValue, strTemp.toLatin1().data());
  strTemp = m_edtCdcValue2->text();
  FIELDCOPY(stBlh.sCdcValueEnd, strTemp.toLatin1().data());

  // 产品
  m_tabProduct1->getSelTab(vctSelect);
  if (vctSelect.size() == 1 && vctSelect[0] == 0) {
    stBlh.nTypeNew[0] = CBondContainer::newBondAll;
  } else {
    int idx = 0;
    m_tabProduct2->getSelTabId(vctSelect);
    for (int i = 0; i < (int)vctSelect.size(); ++i) {
      stBlh.nTypeNew[idx++] = vctSelect[i];
    }

    m_tabProduct3->getSelTabId(vctSelect);
    for (int i = 0; i < (int)vctSelect.size(); ++i) {
      stBlh.nTypeNew[idx++] = vctSelect[i];
    }

    m_tabProduct4->getSelTabId(vctSelect);
    for (int i = 0; i < (int)vctSelect.size(); ++i) {
      stBlh.nTypeNew[idx++] = vctSelect[i];
    }

    m_tabProduct5->getSelTabId(vctSelect);
    for (int i = 0; i < (int)vctSelect.size(); ++i) {
      stBlh.nTypeNew[idx++] = vctSelect[i];
    }
  }

  // 地方债
  _getTabSelect(m_tabLocalBond, nLocalBond, CBondContainer::LocalBondAll);

  // 地方债专项
  const QStringList& lstSubType = m_treeLocalBondSpecial->getSelectItemData();
  int nIndex = 0;
  for (auto it : lstSubType) {
    FIELDCOPY(stBlh.szCategoryFlag[nIndex], it.toLatin1().data());
    nIndex++;
  }

  // 地方债地区
  std::vector<std::string> vctSelCode;
  m_tabLocalBondArea->getSelTabUserData(vctSelCode);

  const QStringList& lstLocalBondArea =
      m_treeLocalBondArea->getSelectItemData();
  for (auto it : lstLocalBondArea) {
    vctSelCode.push_back(it.toLatin1().data());
  }
  for (int i = 0; i < (int)vctSelCode.size(); ++i) {
    FIELDCOPY(stBlh.szLocalBondArea[i], vctSelCode[i].c_str());
  }

  // NCD
  m_tabBondNCD->getSelTab(vctSelect);

  const QStringList& lstNCD = m_treeNCD->getSelectItemData();
  for (auto it : lstNCD) {
    vctSelect.push_back(it.toInt());
  }
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nNCDRating[i] = CBondContainer::NCDRatingAll + vctSelect[i];
  }

  // 期限
  m_fltTerm->getSelTab(vctSelect);
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nRange[i] = CBondContainer::RangeAll + vctSelect[i];
  }

  FIELDCOPY(stBlh.sDate1, m_edtTermBegin->text().toStdString().c_str());
  FIELDCOPY(stBlh.sDate2, m_edtTermEnd->text().toStdString().c_str());
  if (strcmp(stBlh.sDate1, "") != 0 || strcmp(stBlh.sDate2, "") != 0) {
    if (m_bShowDY)
      stBlh.nRange[0] = CBondContainer::RangeOther;
    else
      stBlh.nRange[0] = CBondContainer::RangeDate;
  } else {
    if ((int)vctSelect.size() == 1 && vctSelect[0] == 0)
      stBlh.nRange[0] = CBondContainer::RangeAll;
  }

  // 发行人
  nIndex = 0;
  for (auto itor = m_vctIssuer.begin();
       itor != m_vctIssuer.end() && nIndex < BLH_ISSUERCOUNT;
       itor++, nIndex++) {
    FIELDCOPY(stBlh.szIssuer[nIndex], (*itor).c_str());
  }

  // 担保人
  nIndex = 0;
  for (auto itor = m_vctGuarantor.begin();
       itor != m_vctGuarantor.end() && nIndex < BLH_ISSUERCOUNT;
       itor++, nIndex++) {
    FIELDCOPY(stBlh.szGuarantor[nIndex], (*itor).c_str());
  }

  // 热门
  int idx = 0;
  m_tabHot1->getSelTabId(vctSelect);
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nPopular[idx++] = vctSelect[i];
  }

  m_tabHot2->getSelTabId(vctSelect);
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nPopular[idx++] = vctSelect[i];
  }

  m_tabHot3->getSelTabId(vctSelect);
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nPopular[idx++] = vctSelect[i];
  }

  m_tabHot4->getSelTabId(vctSelect);
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nPopular[idx++] = vctSelect[i];
  }

  m_tabHot5->getSelTabId(vctSelect);
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nPopular[idx++] = vctSelect[i];
  }

  // 城投
  _getTabSelect(m_tabInvest, nMunicp, CBondContainer::MunicAll);
  // 城投层次
  _getTabSelect(m_tabPformType, nPlatform, CBondContainer::PlatforamAll);

  // 城投地区
  const QStringList& lstMuniArea = m_treeMuniArea->getSelectItemData();
  nIndex = 0;
  for (auto it : lstMuniArea) {
    FIELDCOPY(stBlh.szMuniArea[nIndex], it.toLatin1().data());
    nIndex++;
  }

  // 高收益债
  idx = 0;
  m_tabGrade->getSelTabId(vctSelect);
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nHighYieldBond[idx++] = vctSelect[i];
  }

  // 银行业
  _getTabSelect(m_tabBank, nBankBond, CBondContainer::BankAll);

  // 行业
  const QStringList& lstSector = m_treeSector->getSelectItemData();
  nIndex = 0;
  for (auto it : lstSector) {
    FIELDCOPY(stBlh.szSector2021[nIndex], it.toLatin1().data());
    nIndex++;
  }

  // 企业
  _getTabSelect(m_tabCorp, nInstion, CBondContainer::InstAll);

  // 担保
  idx = 0;
  m_tabBondAssure->getSelTabId(vctSelect);
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nWarrant[idx++] = vctSelect[i];
  }

  // 三方担保
  idx = 0;
  m_tabThirdPartGuarantee->getSelTabId(vctSelect);
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nThirdPartyGuarantee[idx++] = vctSelect[i];
  }

  // 主体
  m_tabIssuerRating->getSelTab(vctSelect);

  const QStringList& lstIssuerRating = m_treeIssuerRating->getSelectItemData();
  for (auto it : lstIssuerRating) {
    vctSelect.push_back(it.toInt());
  }
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nIssuerRating[i] = CBondContainer::RatingAll + vctSelect[i];
  }

  // 中债资信
  if (m_hasRatingRightsOfCBR) {
    m_tabCBRRating->getSelTab(vctSelect);

    const QStringList& lstCBRRating = m_treeCBRRating->getSelectItemData();
    for (auto it : lstCBRRating) {
      vctSelect.push_back(it.toInt());
    }
    for (int i = 0; i < (int)vctSelect.size(); ++i) {
      stBlh.nCBRRating[i] = CBondContainer::CBRRatingAll + vctSelect[i];
    }
  } else {
    memset(&stBlh.nCBRRating, 0, sizeof(stBlh.nCBRRating));
    stBlh.nCBRRating[0] = CBondContainer::CBRRatingAll;
  }

  // 展望
  _getTabSelect(m_tabOutlook, nOutlookRating, CBondContainer::OutlookRatingAll);

  // 债项
  m_tabBondRating->getSelTab(vctSelect);

  const QStringList& lstBondRating = m_treeBondRating->getSelectItemData();
  for (auto it : lstBondRating) {
    vctSelect.push_back(it.toInt());
  }
  for (int i = 0; i < (int)vctSelect.size(); ++i) {
    stBlh.nDebtRating[i] = CBondContainer::DRatingAll + vctSelect[i];
  }

  // 中债隐含
  if (m_hasRatingRightsOfCDC) {
    m_tabCDCRating->getSelTab(vctSelect);

    const QStringList& lstCDCRating = m_treeCDCRating->getSelectItemData();
    for (auto it : lstCDCRating) {
      vctSelect.push_back(it.toInt());
    }
    for (int i = 0; i < (int)vctSelect.size(); ++i) {
      stBlh.nCDCRating[i] = CBondContainer::CDCRatingAll + vctSelect[i];
    }
  } else {
    memset(&stBlh.nCDCRating, 0, sizeof(stBlh.nCDCRating));
    stBlh.nCDCRating[0] = CBondContainer::CDCRatingAll;
  }

  // 中证隐含
  if (m_hasRatingRightsOfCSI) {
    m_tabCSIRating->getSelTab(vctSelect);

    const QStringList& lstCSIRating = m_treeCSIRating->getSelectItemData();
    for (auto it : lstCSIRating) {
      vctSelect.push_back(it.toInt());
    }
    for (int i = 0; i < (int)vctSelect.size(); ++i) {
      stBlh.nCSIRating[i] = CBondContainer::CSIRatingAll + vctSelect[i];
    }
  } else {
    memset(&stBlh.nCSIRating, 0, sizeof(stBlh.nCSIRating));
    stBlh.nCSIRating[0] = CBondContainer::CSIRatingAll;
  }

  // 发行
  _getTabSelect(m_tabAssetStatus, nAssetStatus, CBondContainer::AssetAll);
  // 含权
  _getTabSelect(m_tabOptionType, nRightEx, CBondContainer::RightExAll);
  // 偿还方式
  _getTabSelect(m_tabPrincipayPayType, nPrincipalPayType,
                CBondContainer::PPTAll);
  // 永续债
  _getTabSelect(m_tabETSBond, nETSBond, CBondContainer::ETSBondAll);
  // 次级债
  _getTabSelect(m_tabSubordinatedBond, nSubOrdinate, CBondContainer::SubOrdAll);
  // 上市场所
  _getTabSelect(m_tabListedVenues, nListedPlace, CBondContainer::kExchAll);
  // 利率方式
  _getTabSelect(m_tabRateType, nCouponType, CBondContainer::AssetAll);
  // 做市标的
  _getTabSelect(m_tabMarketMakeTarget, nMarketMakeTarget,
                CBondContainer::kMarketMakeAll);

  // 发行年份
  nIndex = 0;
  m_tabYear->getSelTabId(vctSelect);
  for (auto it : vctSelect) {
    stBlh.nIssueYear[nIndex] = it;
    nIndex++;
  }

  const QStringList& lstYear = m_treeYear->getSelectItemData();
  for (auto it : lstYear) {
    stBlh.nIssueYear[nIndex] = it.toInt();
    nIndex++;
  }

  // 地区
  const QStringList& lstArea = m_treeArea->getSelectItemData();
  nIndex = 0;
  for (auto it : lstArea) {
    FIELDCOPY(stBlh.szArea[nIndex], it.toLatin1().data());
    nIndex++;
  }

  // 细分
  const QStringList& lstSubType2 = m_treeSubType->getSelectItemData();
  nIndex = 0;
  for (auto it : lstSubType2) {
    FIELDCOPY(stBlh.szSubType[nIndex], it.toLatin1().data());
    nIndex++;
  }

  // 债券流动性
  m_tabBondLiquidity->getSelTab(vctSelect);
  memset(stBlh.sBondLiquidity, 0, sizeof(stBlh.sBondLiquidity));
  char* p = stBlh.sBondLiquidity;
  for (int i = 0; i < (int)vctSelect.size(); i++) {
    int nSelect = vctSelect[i];
    switch (nSelect) {
      case 0:
        memset(stBlh.sBondLiquidity, 0, sizeof(stBlh.sBondLiquidity));
        break;
      case 1:
        *p = 'S';
        p++;
        break;
      case 2:
        *p = 'A';
        p++;
        break;
      case 3:
        *p = 'B';
        p++;
        break;
      case 4:
        *p = 'C';
        p++;
        break;
      case 5:
        *p = 'D';
        p++;
        break;
      default:
        break;
    }
  }

  // 主体流动性
  m_tabIssuerLiquidity->getSelTab(vctSelect);
  memset(stBlh.sIssuerLiquidity, 0, sizeof(stBlh.sIssuerLiquidity));
  p = stBlh.sIssuerLiquidity;
  for (int i = 0; i < (int)vctSelect.size(); i++) {
    int nSelect = vctSelect[i];
    switch (nSelect) {
      case 0:
        memset(stBlh.sIssuerLiquidity, 0, sizeof(stBlh.sIssuerLiquidity));
        break;
      case 1:
        *p = 'S';
        p++;
        break;
      case 2:
        *p = 'A';
        p++;
        break;
      case 3:
        *p = 'B';
        p++;
        break;
      case 4:
        *p = 'C';
        p++;
        break;
      case 5:
        *p = 'D';
        p++;
        break;
      default:
        break;
    }
  }
}

QLineEdit* CreateLineEdit(QWidget* pParent, int w = editWidth) {
  QLineEdit* pEdit = new QLineEdit(pParent);
  pEdit->setStyleSheet(
      QString(pEdit->styleSheet() + "QLineEdit {border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));
  if (w > 0)
    pEdit->setFixedSize(w, lineHeight);
  else
    pEdit->setFixedHeight(lineHeight);
  return pEdit;
}

SLineEdit* CreateSLineEdit(QWidget* pParent, int w = editWidth) {
  SLineEdit* pEdit = new SLineEdit("", pParent);
  pEdit->setStyleSheet(
      QString(pEdit->styleSheet() + "QLineEdit {border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));
  if (w > 0)
    pEdit->setFixedSize(w, lineHeight);
  else
    pEdit->setFixedHeight(lineHeight);
  return pEdit;
}

QLabel* CreateLabel(QString sName, QWidget* pParent) {
  QLabel* pLabel = new QLabel(sName, pParent);
  pLabel->setStyleSheet(labelStyle);
  pLabel->setContentsMargins(8, 0, 8, 0);
  return pLabel;
}

QLabel* CreateHifLabel(QString sName, QWidget* pParent) {
  QLabel* pLabel = new QLabel(sName, pParent);
  pLabel->setStyleSheet(labelStyle2);
  pLabel->setFixedSize(gap, lineHeight);
  return pLabel;
}

void BestQuoteFilter::createFilterQuoteType(QBoxLayout* layout) {
  m_tabQuoteType = new SFilterButton(this);
  m_tabQuoteType->setName(NewStringTable::strQuoteType(-1));
  m_tabQuoteType->setNameWidth(labelWidth);
  m_tabQuoteType->setMultiSel(true);

  for (int i = 0; i < 4; i++) {
    m_tabQuoteType->addTab(NewStringTable::strQuoteType(i));
  }

  m_tabQuoteType->selectTab(0);
  connect(m_tabQuoteType, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterButtonClick);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 80, 0);
  subLayout->addWidget(m_tabQuoteType);
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterPrice1(QBoxLayout* layout) {
  QHBoxLayout* priceLayout = new QHBoxLayout();
  priceLayout->setContentsMargins(0, 0, 0, 0);
  priceLayout->setSpacing(gap);

  QVBoxLayout* priceLeft = new QVBoxLayout();
  priceLeft->setContentsMargins(0, 0, 0, 0);
  priceLeft->setSpacing(gap);
  QVBoxLayout* priceRight = new QVBoxLayout();
  priceRight->setContentsMargins(0, 0, 0, 0);
  priceRight->setSpacing(gap);

  priceLayout->addLayout(priceLeft);
  priceLayout->addLayout(priceRight);

  {
    QHBoxLayout* lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);

    m_btnShowAll = new SButtonShowAll(this);
    m_btnShowAll->setText("SHOW ALL");
    m_btnShowAll->setFixedHeight(lineHeight);
    m_btnShowAll->setChecked(true);
    lp->addWidget(m_btnShowAll);

    m_chkValid = new SCheckEx(tr("有效报价"), this);
    m_chkValid->setIndex(id_chk_valid);
    m_chkValid->setFixedSize(editWidth * 2 + gap * 3, lineHeight);
    lp->addWidget(m_chkValid);
    priceLeft->addLayout(lp);

    lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);

    m_chkBothValid = new SCheckEx(tr("双边"), this);
    m_chkBothValid->setIndex(id_chk_bothvalid);
    lp->addWidget(m_chkBothValid);

    m_chkBidValid = new SCheckEx("Bid", this);
    m_chkBidValid->setIndex(id_chk_bidvalid);
    m_chkBidValid->setFixedSize(editWidth + gap, lineHeight);
    lp->addWidget(m_chkBidValid);

    m_chkOfrValid = new SCheckEx("Ofr", this);
    m_chkOfrValid->setIndex(id_chk_ofrvalid);
    m_chkOfrValid->setFixedSize(editWidth + gap, lineHeight);
    lp->addWidget(m_chkOfrValid);
    priceRight->addLayout(lp);
  }

  connect(m_btnShowAll, &QPushButton::clicked, this,
          &BestQuoteFilter::onShowAll);
  connect(m_chkValid, &SCheckEx::stateChanged, this,
          &BestQuoteFilter::onCheckChange);
  connect(m_chkBothValid, &SCheckEx::stateChanged, this,
          &BestQuoteFilter::onCheckChange);
  connect(m_chkBidValid, &SCheckEx::stateChanged, this,
          &BestQuoteFilter::onCheckChange);
  connect(m_chkOfrValid, &SCheckEx::stateChanged, this,
          &BestQuoteFilter::onCheckChange);

  layout->addLayout(priceLayout);
}

void BestQuoteFilter::createFilterPrice2(QBoxLayout* layout) {
  QHBoxLayout* priceLayout = new QHBoxLayout();
  priceLayout->setContentsMargins(0, 0, 0, 0);
  priceLayout->setSpacing(gap);

  QVBoxLayout* priceLeft = new QVBoxLayout();
  priceLeft->setContentsMargins(0, 0, 0, 0);
  priceLeft->setSpacing(gap);
  QVBoxLayout* priceRight = new QVBoxLayout();
  priceRight->setContentsMargins(0, 0, 0, 0);
  priceRight->setSpacing(gap);

  priceLayout->addLayout(priceLeft);
  priceLayout->addLayout(priceRight);

  {
    QHBoxLayout* lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);

    m_rdoYield = new SCheckEx(tr("收益率"), this);
    m_rdoYield->setSelectType(SCheckEx::SelectType::Radio);
    m_rdoYield->setIndex(0);
    lp->addWidget(m_rdoYield);
    priceLeft->addLayout(lp);

    lp = new QHBoxLayout();
    m_rdoPrice = new SCheckEx(tr("净价"), this);
    m_rdoPrice->setSelectType(SCheckEx::SelectType::Radio);
    m_rdoPrice->setIndex(1);
    lp->addWidget(m_rdoPrice);
    priceRight->addLayout(lp);
  }
  {
    QHBoxLayout* lp = new QHBoxLayout();
    QLabel* pLabel = CreateLabel("Bid", this);
    lp->addWidget(pLabel);

    m_edtBid = CreateLineEdit(this);
    lp->addWidget(m_edtBid);

    pLabel = CreateHifLabel("-", this);
    lp->addWidget(pLabel);

    m_edtBid2 = CreateLineEdit(this);
    lp->addWidget(m_edtBid2);
    priceLeft->addLayout(lp);

    lp = new QHBoxLayout();
    pLabel = CreateLabel("Ofr", this);
    lp->addWidget(pLabel);

    m_edtOfr = CreateLineEdit(this);
    lp->addWidget(m_edtOfr);

    pLabel = CreateHifLabel("-", this);
    lp->addWidget(pLabel);

    m_edtOfr2 = CreateLineEdit(this);
    lp->addWidget(m_edtOfr2);
    priceRight->addLayout(lp);
  }
  {
    QHBoxLayout* lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);

    QLabel* pLabel = CreateLabel(tr("Bid-中债"), this);
    lp->addWidget(pLabel);

    m_edtBidCdc = CreateLineEdit(this);
    lp->addWidget(m_edtBidCdc);

    pLabel = CreateHifLabel("-", this);
    lp->addWidget(pLabel);

    m_edtBidCdc2 = CreateLineEdit(this);
    lp->addWidget(m_edtBidCdc2);
    priceLeft->addLayout(lp);

    lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);
    pLabel = CreateLabel(tr("中债-Ofr"), this);
    lp->addWidget(pLabel);

    m_edtCdcOfr = CreateLineEdit(this);
    lp->addWidget(m_edtCdcOfr);

    pLabel = CreateHifLabel("-", this);
    lp->addWidget(pLabel);

    m_edtCdcOfr2 = CreateLineEdit(this);
    lp->addWidget(m_edtCdcOfr2);

    priceRight->addLayout(lp);
  }
  {
    QHBoxLayout* lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);

    QLabel* pLabel = CreateLabel("Vol.Bid", this);
    lp->addWidget(pLabel);
    lp->addSpacing(lineHeight + gap);

    m_edtVolBid = CreateLineEdit(this, 80);
    lp->addWidget(m_edtVolBid);
    priceLeft->addLayout(lp);

    lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);

    pLabel = CreateLabel("Vol.Ofr", this);
    lp->addWidget(pLabel);
    lp->addSpacing(lineHeight + gap);

    m_edtVolOfr = CreateLineEdit(this, 80);
    lp->addWidget(m_edtVolOfr);

    priceRight->addLayout(lp);
  }
  {
    QHBoxLayout* lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);

    QLabel* pLabel = CreateLabel(tr("Bid-Ofr"), this);
    lp->addWidget(pLabel);

    m_edtBidOfr = CreateLineEdit(this);
    lp->addWidget(m_edtBidOfr);

    pLabel = CreateHifLabel("-", this);
    lp->addWidget(pLabel);

    m_edtBidOfr2 = CreateLineEdit(this);
    lp->addWidget(m_edtBidOfr2);
    priceLeft->addLayout(lp);

    lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);
    pLabel = CreateLabel(tr("票面利率"), this);
    lp->addWidget(pLabel);

    m_edtCouponRate = CreateLineEdit(this);
    lp->addWidget(m_edtCouponRate);

    pLabel = CreateHifLabel("-", this);
    lp->addWidget(pLabel);

    m_edtCouponRate2 = CreateLineEdit(this);
    lp->addWidget(m_edtCouponRate2);
    priceRight->addLayout(lp);
  }
  {
    QHBoxLayout* lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);

    QLabel* pLabel = CreateLabel(tr("中债估值"), this);
    lp->addWidget(pLabel);

    m_edtCdcValue = CreateLineEdit(this);
    lp->addWidget(m_edtCdcValue);

    pLabel = CreateHifLabel("-", this);
    lp->addWidget(pLabel);

    m_edtCdcValue2 = CreateLineEdit(this);
    lp->addWidget(m_edtCdcValue2);
    priceLeft->addLayout(lp);

    lp = new QHBoxLayout();
    lp->setContentsMargins(0, 0, 0, 0);
    lp->setSpacing(gap);
    lp->addSpacerItem(
        new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Fixed));

    m_btnPriceFilter = new QPushButton(tr("筛选"), this);
    m_btnPriceFilter->setFixedSize(editWidth * 2 + gap * 3, lineHeight);
    lp->addWidget(m_btnPriceFilter);
    priceRight->addLayout(lp);
  }

  connect(m_rdoYield, &SCheckEx::stateChanged, this,
          &BestQuoteFilter::onRadioStateChanged);
  connect(m_rdoPrice, &SCheckEx::stateChanged, this,
          &BestQuoteFilter::onRadioStateChanged);
  connect(m_btnPriceFilter, &QPushButton::clicked, this,
          &BestQuoteFilter::onFilterButtonClick);

  layout->addLayout(priceLayout);
}

void BestQuoteFilter::createFilterProduct1(QBoxLayout* layout) {
  m_tabProduct1 = new SFilterButton(this, "ButtonNormal");
  m_tabProduct1->setMultiSel(true);
  m_tabProduct1->setName(NewStringTable::strFilterProduct1(-1));
  m_tabProduct1->setNameWidth(labelWidth);
  m_tabProduct1->setVirtualHead2();

  for (int i = 0; i < 4; i++) {
    m_tabProduct1->addTab(NewStringTable::strFilterProduct1(i));
  }

  m_tabProduct1->selectTab(0);
  connect(m_tabProduct1, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterProduct1Click);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 114, 0);
  subLayout->addWidget(m_tabProduct1);
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterProduct2(QBoxLayout* layout) {
  m_tabProduct2 = new SFilterButton(this);
  m_tabProduct2->setMultiSel(true);
  m_tabProduct2->setName(NewStringTable::strFilterProduct2(-1));
  m_tabProduct2->setNameWidth(labelWidth);
  m_tabProduct2->setVirtualHead();

  for (int i = 0; i < 5; i++) {
    m_tabProduct2->addTab(NewStringTable::strFilterProduct2(i),
                          CBondContainer::newBondCountry + i);
  }

  connect(m_tabProduct2, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterProduct2Click);
  layout->addWidget(m_tabProduct2);
}

void BestQuoteFilter::createFilterProduct3(QBoxLayout* layout) {
  m_tabProduct3 = new SFilterButton(this);
  m_tabProduct3->setMultiSel(true);
  m_tabProduct3->setName(NewStringTable::strFilterProduct3(-1));
  m_tabProduct3->setNameWidth(labelWidth);
  m_tabProduct3->setVirtualHead();

  for (int i = 0; i < 5; i++) {
    if (0 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("短融");
      item1.id = CBondContainer::newBondShort_Short;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("超短融");
      item2.id = CBondContainer::newBondShort_Super;
      vctSub.push_back(item2);
      m_tabProduct3->addTab(NewStringTable::strFilterProduct3(i),
                            CBondContainer::newBondShort, "", &vctSub);
    } else if (3 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("公募");
      item1.id = CBondContainer::newBondCOP_Null;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("小公募");
      item2.id = CBondContainer::newBondCOP_Pub;
      vctSub.push_back(item2);

      SFilterSubMenuItem item3;
      item3.name = tr("私募");
      item3.id = CBondContainer::newBondCOP_Pri;
      vctSub.push_back(item3);
      m_tabProduct3->addTab(NewStringTable::strFilterProduct3(i),
                            CBondContainer::newBondCOP, "", &vctSub);
    } else if (4 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("商业银行债");
      item1.id = CBondContainer::newBondBank_Commercial;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("银行二级债");
      item2.id = CBondContainer::newBondBank_Second;
      vctSub.push_back(item2);

      SFilterSubMenuItem item3;
      item3.name = tr("银行永续债");
      item3.id = CBondContainer::newBondBank_Perpetual;
      vctSub.push_back(item3);
      m_tabProduct3->addTab(NewStringTable::strFilterProduct3(i),
                            CBondContainer::newBondBank, "", &vctSub);
    } else {
      m_tabProduct3->addTab(NewStringTable::strFilterProduct3(i),
                            CBondContainer::newBondShort + i);
    }
  }

  connect(m_tabProduct3, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterProduct3Click);
  layout->addWidget(m_tabProduct3);
}

void BestQuoteFilter::createFilterProduct4(QBoxLayout* layout) {
  m_tabProduct4 = new SFilterButton(this);
  m_tabProduct4->setMultiSel(true);
  m_tabProduct4->setName(NewStringTable::strFilterProduct4(-1));
  m_tabProduct4->setNameWidth(labelWidth);
  m_tabProduct4->setVirtualHead();

  for (int i = 0; i < 5; i++) {
    if (0 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("证券公司");
      item1.id = CBondContainer::newBondBroker_Corp;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("证券公司短融");
      item2.id = CBondContainer::newBondBroker_Short;
      vctSub.push_back(item2);

      SFilterSubMenuItem item3;
      item3.name = tr("证券次级");
      item3.id = CBondContainer::newBondBroker_Second;
      vctSub.push_back(item3);
      m_tabProduct4->addTab(NewStringTable::strFilterProduct4(i),
                            CBondContainer::newBondBroker, "", &vctSub);
    } else {
      m_tabProduct4->addTab(NewStringTable::strFilterProduct4(i));
    }
  }

  connect(m_tabProduct4, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterProduct4Click);
  layout->addWidget(m_tabProduct4);
}

void BestQuoteFilter::createFilterProduct5(QBoxLayout* layout) {
  m_tabProduct5 = new SFilterButton(this);
  m_tabProduct5->setMultiSel(true);
  m_tabProduct5->setName(NewStringTable::strFilterProduct5(-1));
  m_tabProduct5->setNameWidth(labelWidth);
  m_tabProduct5->setVirtualHead();

  for (int i = 0; i < 4; i++) {
    m_tabProduct5->addTab(NewStringTable::strFilterProduct5(i));
  }

  connect(m_tabProduct5, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterProduct5Click);
  layout->addWidget(m_tabProduct5);
}

void BestQuoteFilter::createFilterLocalBondSpecial(QBoxLayout* layout) {
  QHBoxLayout* hLayout = new QHBoxLayout();
  hLayout->setContentsMargins(0, 0, 0, 0);
  hLayout->setSpacing(gap);

  m_treeLocalBondSpecial = new SFilterTree(this);  // 地方债专项
  m_treeLocalBondSpecial->setName(
      NewStringTable::strFilterLocalBondSpecial(-1));
  m_treeLocalBondSpecial->setDefaultString(
      NewStringTable::strFilterLocalBondSpecial(0));
  m_treeLocalBondSpecial->setNameWidth(labelWidth);
  m_treeLocalBondSpecial->setFixedHeight(lineHeight);
  m_treeLocalBondSpecial->setFixedWidth(labelWidth + 210);
  m_treeLocalBondSpecial->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  std::vector<std::string> vctCategoryFlagInfo =
      CQBCategoryFlagInfo::instance().GetCategoryFlagInfo();

  STreeData treeData;
  for (int i = 0; i < (int)vctCategoryFlagInfo.size(); ++i) {
    QString szText = QString::fromLocal8Bit(vctCategoryFlagInfo[i].c_str());
    treeData.addChild(szText, szText);
  }

  m_treeLocalBondSpecial->setTreeData(treeData);

  connect(m_treeLocalBondSpecial, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterButtonClick);

  hLayout->addWidget(m_treeLocalBondSpecial);
  hLayout->addSpacerItem(
      new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding));
  layout->addLayout(hLayout);
}

void BestQuoteFilter::createFilterLocalBondArea(QBoxLayout* layout) {
  CQBProvinceInfo& pvinfo = CQBProvinceInfo::instance();
  const std::map<std::string, QBPROVINCEINFO>& stlProvice =
      pvinfo.GetAllProviceInfo();
  const std::vector<std::string> vctCode = {"GDPRN", "SDPRN", "ZJPRN", "JSPRN"};
  std::vector<QBPROVINCEINFO> vecProv;
  for (const auto it : vctCode) {
    auto info = pvinfo.GetProviceInfo(it);
    if (nullptr == info) {
      continue;
    }
    vecProv.push_back(*info);  // 地方债地区
  }
  for (const auto& itor : stlProvice) {
    const QBPROVINCEINFO& stProvince = itor.second;
    if (strcmp(stProvince.Area_Level, "PRN") != 0) continue;

    if (std::find(vctCode.begin(), vctCode.end(), stProvince.Area_Code) !=
        vctCode.end())
      continue;
    vecProv.push_back(stProvince);  // 地方债地区
  }

  m_tabLocalBondArea = new SFilterButton(this);
  m_tabLocalBondArea->setName(NewStringTable::strFilterLocalBondArea(-1));
  m_tabLocalBondArea->setNameWidth(labelWidth);
  m_tabLocalBondArea->setMultiSel(true);

  m_tabLocalBondArea->addTab(NewStringTable::strFilterLocalBondArea(0));
  for (int i = 0; i < 4 && i < (int)vecProv.size(); ++i) {
    m_tabLocalBondArea->addTab(QString::fromLocal8Bit(vecProv[i].Area_Name), 0,
                               vecProv[i].Area_Code);
  }

  connect(m_tabLocalBondArea, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterLocalBondAreaClick1);

  m_treeLocalBondArea = new SFilterTree(this, false, false, "TabBackNormal",
                                        "BorderNormal", 20, 164);  // 地方债地区
  m_treeLocalBondArea->setName("");
  m_treeLocalBondArea->setDefaultString(
      NewStringTable::strFilterLocalBondArea(1));
  m_treeLocalBondArea->setNameWidth(0);
  m_treeLocalBondArea->setLeftOffset(0);
  m_treeLocalBondArea->setFixedWidth(82);
  m_treeLocalBondArea->setDropFixedWidth(118);
  m_treeLocalBondArea->setFixedHeight(lineHeight);
  m_treeLocalBondArea->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  for (int i = 4; i < (int)vecProv.size(); ++i) {
    treeData.addChild(QString::fromLocal8Bit(vecProv[i].Area_Name),
                      vecProv[i].Area_Code);
  }

  m_treeLocalBondArea->setTreeData(treeData);

  connect(m_treeLocalBondArea, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterLocalBondAreaClick2);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 0, 0);
  subLayout->addWidget(m_tabLocalBondArea);
  subLayout->addWidget(m_treeLocalBondArea);
  subLayout->addSpacerItem(
      new QSpacerItem(14, 20, QSizePolicy::Fixed, QSizePolicy::Fixed));
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterNCD(QBoxLayout* layout) {
  m_tabBondNCD = new SFilterButton(this);
  m_tabBondNCD->setName(NewStringTable::strFilterBondNCD(-1));
  m_tabBondNCD->setNameWidth(labelWidth);
  m_tabBondNCD->setMultiSel(true);

  for (int i = 0; i < 5; i++) {
    m_tabBondNCD->addTab(NewStringTable::strFilterBondNCD(i));
  }

  connect(m_tabBondNCD, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterNCDClick1);

  m_treeNCD = new SFilterTree(this, false, false, "TabBackNormal",
                              "BorderNormal", 20, 45);
  m_treeNCD->setName("");
  m_treeNCD->setDefaultString(NewStringTable::strFilterBondNCD(5));
  m_treeNCD->setNameWidth(0);
  m_treeNCD->setLeftOffset(0);
  m_treeNCD->setFixedWidth(82);
  m_treeNCD->setDropFixedWidth(118);
  m_treeNCD->setFixedHeight(lineHeight);
  m_treeNCD->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  for (int i = 6; i < 8; ++i) {
    treeData.addChild(NewStringTable::strFilterBondNCD(i), QString::number(i));
  }

  m_treeNCD->setTreeData(treeData);

  connect(m_treeNCD, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterNCDClick2);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 0, 0);
  subLayout->addWidget(m_tabBondNCD);
  subLayout->addWidget(m_treeNCD);
  subLayout->addSpacerItem(
      new QSpacerItem(14, 20, QSizePolicy::Fixed, QSizePolicy::Fixed));
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterTerm(QBoxLayout* layout) {
  m_fltTerm = new SFilterButton(this);
  m_fltTerm->setMultiSel(true);
  m_fltTerm->setName(NewStringTable::strFilterTerm(-1));
  m_fltTerm->setNameWidth(labelWidth);
  for (int i = 0; i < 13; i++) {
    m_fltTerm->addTab(NewStringTable::strFilterTerm(i));
  }

  if (NewStringTable::strFilterTerm(-1).length() > 0) m_fltTerm->selectTab(0);
  connect(m_fltTerm, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterTermClick);
  layout->addWidget(m_fltTerm);

  QHBoxLayout* hLayout = new QHBoxLayout();
  hLayout->setContentsMargins(labelWidth - 6, 0, 0, 0);
  hLayout->setSpacing(gap);

  m_edtTermBegin = CreateSLineEdit(this, 80);
  hLayout->addWidget(m_edtTermBegin);

  m_btnTerm = new SImageButton(this, "guiframe_daymonthyear");
  m_btnTerm->setToolTip(
      tr("Y=年, M=月, D=天\n 例: 1.5~5Y\n      6M~12M\n      10D~365D"));
  m_btnTerm->setColor(NAME_COLOR("MainTitleBack"), NAME_COLOR("Hover"),
                      NAME_COLOR("Hover"), NAME_COLOR("MainTitleBack"));
  m_btnTerm->setFixedSize(lineHeight, lineHeight);
  hLayout->addWidget(m_btnTerm);
  connect(m_btnTerm, &SImageButton::clicked, this,
          &BestQuoteFilter::onTermClicked);

  m_edtTermEnd = CreateSLineEdit(this, 80);
  hLayout->addWidget(m_edtTermEnd);

  m_btnTermFilter = new QPushButton(tr("筛选"), this);
  m_btnTermFilter->setFixedSize(36, lineHeight);
  hLayout->addWidget(m_btnTermFilter);
  connect(m_btnTermFilter, &QPushButton::clicked, this,
          &BestQuoteFilter::onTermFilterButtonClick);

  connect(m_edtTermBegin, &SLineEdit::clicked, this,
          &BestQuoteFilter::onEditTermBeginClicked);
  connect(m_edtTermEnd, &SLineEdit::clicked, this,
          &BestQuoteFilter::onEditTermEndClicked);

  hLayout->addSpacerItem(
      new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding));
  layout->addLayout(hLayout);
}

void BestQuoteFilter::createFilterIssuer(QBoxLayout* layout) {
  QHBoxLayout* hLayout = new QHBoxLayout();
  hLayout->setContentsMargins(0, 0, 0, 0);
  hLayout->setSpacing(gap);

  QLabel* labelIssuer = new QLabel(tr("发行人"), this);
  labelIssuer->setStyleSheet(
      QString("padding-left: 4px;color:#%1; background-color:#%2;border:1px "
              "solid #%2;border-radius:2px")
          .arg(StyleMgr::instance().color("TitleWord").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("StaticTextBK").rgb(), 0, 16));
  labelIssuer->setFixedSize(labelWidth - gap - 6, lineHeight);

  m_searchIssuer = new KeySearchWidget(this, "SearchBackNormal2", "Hover",
                                       "TipsBorder", 0, true, 20, 9);
  BondFilterIssuerSearchEngine* engine = new BondFilterIssuerSearchEngine();
  engine->setFilterWnd(this);
  m_searchIssuer->setAutoSelect(false);
  m_searchIssuer->setAutoKillFocus(true);
  m_searchIssuer->setEditFocusChangedClearText(false);
  m_searchIssuer->setSearchEngine(engine);
  m_searchIssuer->setFixedWidth(175);
  m_searchIssuer->setFixedHeight(lineHeight);
  m_searchIssuer->setResultDlgMinWidth(300);
  m_searchIssuer->setResultDlgMaxHeight(20 * 8);
  m_searchIssuer->setColumnsWidth(1, 280);
  m_searchIssuer->setPromptText(tr(""));

  m_btnIssuer = new SImageButton(this, "guiframe_filter_drop");
  m_btnIssuer->setColor(NAME_COLOR("MainTitleBack"), NAME_COLOR("Hover"),
                        NAME_COLOR("Hover"), NAME_COLOR("MainTitleBack"));
  m_btnIssuer->setFixedSize(lineHeight, lineHeight);

  m_panelIssuer = new QWidget();
  m_panelIssuer->setFixedSize(50, 24);
  m_panelIssuer->setStyleSheet(
      QString("background-color:#%1;border: 1px solid #%2;")
          .arg(StyleMgr::instance().color("StaticTextBK").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("BorderNormal").rgb(), 0, 16));

  QHBoxLayout* hCalcLayout = new QHBoxLayout();
  hCalcLayout->setContentsMargins(2, 0, 2, 0);
  hCalcLayout->setSpacing(2);
  m_panelIssuer->setLayout(hCalcLayout);

  m_calcIssuer = new FilterLabel("1", m_panelIssuer);
  m_calcIssuer->setFixedSize(22, 22);
  m_calcIssuer->setStyleSheet(
      QString(
          "padding-left: 2px; color:#%1; background-color:#%2; border: none;")
          .arg(StyleMgr::instance().color("Highlight").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("BackNormal").rgb(), 0, 16));
  hCalcLayout->addWidget(m_calcIssuer);
  connect(m_calcIssuer, &FilterLabel::clicked, this,
          &BestQuoteFilter::onIssuerLabelClick);

  SImageButton* btnClear = new SImageButton(this, "widgets_action_clean");
  hCalcLayout->addWidget(btnClear);
  connect(btnClear, &SImageButton::clicked, this,
          &BestQuoteFilter::onBtnIssuerClearClick);

  hLayout->addWidget(labelIssuer);
  hLayout->addWidget(m_searchIssuer);
  hLayout->addWidget(m_btnIssuer);
  hLayout->addWidget(m_panelIssuer);
  hLayout->addSpacerItem(
      new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding));
  layout->addLayout(hLayout);

  m_panelIssuer->hide();

  connect(m_btnIssuer, &SImageButton::clicked, this,
          &BestQuoteFilter::onIssuerClicked);
  connect(m_searchIssuer, &KeySearchWidget::resultClear, this,
          &BestQuoteFilter::onEditIssuerResultClear);
}

void BestQuoteFilter::createFilterHot1(QBoxLayout* layout) {
  m_tabHot1 = new SFilterButton(this);
  m_tabHot1->setMultiSel(true);
  m_tabHot1->setName(NewStringTable::strFilterHot1(-1));
  m_tabHot1->setNameWidth(labelWidth);

  for (int i = 0; i < 4; i++) {
    m_tabHot1->addTab(NewStringTable::strFilterHot1(i),
                      CBondContainer::HotAll + i);
  }

  connect(m_tabHot1, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterHot1Click);
  layout->addWidget(m_tabHot1);
}

void BestQuoteFilter::createFilterHot2(QBoxLayout* layout) {
  m_tabHot2 = new SFilterButton(this);
  m_tabHot2->setMultiSel(true);
  m_tabHot2->setName(NewStringTable::strFilterHot2(-1));
  m_tabHot2->setNameWidth(labelWidth);
  m_tabHot2->setVirtualHead();

  for (int i = 0; i < 5; i++) {
    m_tabHot2->addTab(NewStringTable::strFilterHot2(i),
                      CBondContainer::HotInsuranceTier2 + i);
  }

  connect(m_tabHot2, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterHot2Click);
  layout->addWidget(m_tabHot2);
}

void BestQuoteFilter::createFilterHot3(QBoxLayout* layout) {
  m_tabHot3 = new SFilterButton(this);
  m_tabHot3->setName(NewStringTable::strFilterHot3(-1));
  m_tabHot3->setNameWidth(labelWidth);
  m_tabHot3->setMultiSel(true);
  m_tabHot3->setVirtualHead();

  for (int i = 0; i < 4; i++) {
    if (0 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("煤炭");
      item1.id = CBondContainer::HotCoal;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("钢铁");
      item2.id = CBondContainer::HotSteel;
      vctSub.push_back(item2);

      SFilterSubMenuItem item3;
      item3.name = tr("水泥");
      item3.id = CBondContainer::HotCement;
      vctSub.push_back(item3);
      m_tabHot3->addTab(NewStringTable::strFilterHot3(i),
                        CBondContainer::HotOverCapacity, "", &vctSub);
    } else if (1 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("电力");
      item1.id = CBondContainer::HotElectricPower;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("交运");
      item2.id = CBondContainer::HotTransportation;
      vctSub.push_back(item2);
      m_tabHot3->addTab(NewStringTable::strFilterHot3(i),
                        CBondContainer::HotPublicUtilities, "", &vctSub);
    } else if (2 == i) {
      m_tabHot3->addTab(NewStringTable::strFilterHot3(i),
                        CBondContainer::HotListedCompany);
    } else if (3 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("绿色债");
      item1.id = CBondContainer::HotGreenBond;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("社会债");
      item2.id = CBondContainer::HotSociety;
      vctSub.push_back(item2);

      SFilterSubMenuItem item3;
      item3.name = tr("可持续发展");
      item3.id = CBondContainer::HotSustanable;
      vctSub.push_back(item3);
      m_tabHot3->addTab(NewStringTable::strFilterHot3(i),
                        CBondContainer::HotESG, "", &vctSub);
    }
  }

  connect(m_tabHot3, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterHot3Click);
  layout->addWidget(m_tabHot3);
}

void BestQuoteFilter::createFilterHot4(QBoxLayout* layout) {
  m_tabHot4 = new SFilterButton(this);
  m_tabHot4->setMultiSel(true);
  m_tabHot4->setName(NewStringTable::strFilterHot4(-1));
  m_tabHot4->setNameWidth(labelWidth);
  m_tabHot4->setVirtualHead();

  for (int i = 0; i < 5; i++) {
    m_tabHot4->addTab(NewStringTable::strFilterHot4(i),
                      CBondContainer::HotMicroBusiness + i);
  }

  connect(m_tabHot4, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterHot4Click);
  layout->addWidget(m_tabHot4);
}

void BestQuoteFilter::createFilterHot5(QBoxLayout* layout) {
  m_tabHot5 = new SFilterButton(this);
  m_tabHot5->setName(NewStringTable::strFilterHot5(-1));
  m_tabHot5->setNameWidth(labelWidth);
  m_tabHot5->setMultiSel(true);
  m_tabHot5->setVirtualHead();

  for (int i = 0; i < 2; i++) {
    m_tabHot5->addTab(NewStringTable::strFilterHot5(i),
                      CBondContainer::HotNewIssues + i);
  }

  connect(m_tabHot5, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterHot5Click);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 182, 0);
  subLayout->addWidget(m_tabHot5);
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterMuniArea(QBoxLayout* layout) {
  QHBoxLayout* hLayout = new QHBoxLayout();
  hLayout->setContentsMargins(0, 0, 0, 0);
  hLayout->setSpacing(gap);

  m_treeMuniArea = new SFilterTree(this);  // 城投地区
  m_treeMuniArea->setName(NewStringTable::strFilterMuniArea(-1));
  m_treeMuniArea->setDefaultString(NewStringTable::strFilterMuniArea(0));
  m_treeMuniArea->setNameWidth(labelWidth);
  m_treeMuniArea->setFixedHeight(lineHeight);
  m_treeMuniArea->setFixedWidth(labelWidth + 210);
  m_treeMuniArea->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  std::map<std::string, QBPROVINCEINFO>& stlProvice =
      CQBProvinceInfo::instance().GetAllProviceInfo();
  std::map<std::string, QBPROVINCEINFO>::iterator itor;
  for (itor = stlProvice.begin(); itor != stlProvice.end(); itor++) {
    STreeData data;
    STreeData subdata1, subdata2, subdata3;
    QBPROVINCEINFO stProvince = itor->second;
    if (strcmp(stProvince.Area_Level, "PRN") == 0) {
      data.m_szText = QString::fromLocal8Bit(stProvince.Area_Name);
      data.m_szData = QString::fromLocal8Bit(stProvince.Area_Code);

      subdata1.m_szText = data.m_szText + tr("：省本级");
      subdata1.m_szData = data.m_szData;
      data.addChild(subdata1);

      subdata2.m_szText = data.m_szText + tr("：所有市");
      subdata2.m_szData = data.m_szData;
    } else {
      continue;
    }

    std::map<std::string, QBPROVINCEINFO>::iterator itor2;
    for (itor2 = stlProvice.begin(); itor2 != stlProvice.end(); itor2++) {
      QBPROVINCEINFO province = itor2->second;
      if (strcmp(province.Area_Level, "PRN") == 0 ||
          strcmp(province.Area_Level, "CTY") == 0 ||
          strcmp(province.Area_Level, "TWN") == 0) {
      } else {
        continue;
      }

      // 上海、北京、天津、重庆的区县(TWN) 要显示在所有市中
      bool isSpcailPRN = false;
      if (strcmp(province.Area_Upper_Grade_Code, "SHPRN") == 0 ||
          strcmp(province.Area_Upper_Grade_Code, "BJPRN") == 0 ||
          strcmp(province.Area_Upper_Grade_Code, "TJPRN") == 0 ||
          strcmp(province.Area_Upper_Grade_Code, "CQPRN") == 0) {
        isSpcailPRN = true;
      }

      if (strcmp(province.Area_Level, "CTY") != 0 &&
          !isSpcailPRN) {  // 筛选出 xx省的xx区 置于 省的所有市中
        continue;
      }

      QString strPRN = province.Area_Upper_Grade_Code;
      if (strPRN == data.m_szData) {
        STreeData leafData;
        leafData.m_szText = QString::fromLocal8Bit(province.Area_Name);
        leafData.m_szData = QString::fromLocal8Bit(province.Area_Code);
        subdata2.addChild(leafData);
      }
    }

    data.addChild(subdata2);

    subdata3.m_szText = data.m_szText + tr("：区县级");
    subdata3.m_szData = data.m_szData;
    data.addChild(subdata3);

    treeData.addChild(data);
  }

  m_treeMuniArea->setTreeData(treeData);

  connect(m_treeMuniArea, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterButtonClick);

  hLayout->addWidget(m_treeMuniArea);
  hLayout->addSpacerItem(
      new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding));
  layout->addLayout(hLayout);
}

void BestQuoteFilter::createFilterGrade(QBoxLayout* layout) {
  m_tabGrade = new SFilterButton(this);
  m_tabGrade->setName(NewStringTable::strFilterGrade(-1));
  m_tabGrade->setNameWidth(labelWidth);
  m_tabGrade->setMultiSel(true);

  for (int i = 0; i < 5; i++) {
    if (1 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("西南");
      item1.id = CBondContainer::HYBMunicipal_SouthWest;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("西北");
      item2.id = CBondContainer::HYBMunicipal_NorthWest;
      vctSub.push_back(item2);

      SFilterSubMenuItem item3;
      item3.name = tr("东北");
      item3.id = CBondContainer::HYBMunicipal_NorthEast;
      vctSub.push_back(item3);

      SFilterSubMenuItem item4;
      item4.name = tr("华中");
      item4.id = CBondContainer::HYBMunicipal_Center;
      vctSub.push_back(item4);

      SFilterSubMenuItem item5;
      item5.name = tr("其他");
      item5.id = CBondContainer::HYBMunicipal_Other;
      vctSub.push_back(item5);
      m_tabGrade->addTab(NewStringTable::strFilterGrade(i),
                         CBondContainer::HYBMunicipal, "", &vctSub);
    } else if (2 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("地产");
      item1.id = CBondContainer::HYBIndustrial_Estate;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("其他");
      item2.id = CBondContainer::HYBIndustrial_Other;
      vctSub.push_back(item2);
      m_tabGrade->addTab(NewStringTable::strFilterGrade(i),
                         CBondContainer::HYBIndustrial, "", &vctSub);
    } else {
      m_tabGrade->addTab(NewStringTable::strFilterGrade(i),
                         CBondContainer::HYBAll + i);
    }
  }

  connect(m_tabGrade, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterButtonClick);
  layout->addWidget(m_tabGrade);
}

void BestQuoteFilter::createFilterAssure(QBoxLayout* layout) {
  m_tabBondAssure = new SFilterButton(this);
  m_tabBondAssure->setName(NewStringTable::strFilterBondAssure(-1));
  m_tabBondAssure->setNameWidth(labelWidth);
  m_tabBondAssure->setMultiSel(true);

  for (int i = 0; i < 3; i++) {
    if (0 == i) {
      m_tabBondAssure->addTab(NewStringTable::strFilterBondAssure(i),
                              CBondContainer::WarrAll);
    } else if (1 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("担保人");
      item1.id = CBondContainer::WarrPeople;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("担保物");
      item2.id = CBondContainer::WarrObject;
      vctSub.push_back(item2);

      SFilterSubMenuItem item3;
      item3.name = tr("有缓释凭证");
      item3.id = CBondContainer::WarrCRM;
      vctSub.push_back(item3);

      SFilterSubMenuItem item4;
      item4.name = tr("有联结票据");
      item4.id = CBondContainer::WarrCLN;
      vctSub.push_back(item4);
      m_tabBondAssure->addTab(NewStringTable::strFilterBondAssure(i),
                              CBondContainer::WarrYes, "", &vctSub);
    } else if (2 == i) {
      m_tabBondAssure->addTab(NewStringTable::strFilterBondAssure(i),
                              CBondContainer::WarrOther);
    }
  }

  connect(m_tabBondAssure, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterButtonClick);
  layout->addWidget(m_tabBondAssure);
}

void BestQuoteFilter::createThirdPartGuarantee(QBoxLayout* layout) {
  m_tabThirdPartGuarantee = new SFilterButton(this);
  m_tabThirdPartGuarantee->setName(
      NewStringTable::strFilterThirdPartGuarantee(-1));
  m_tabThirdPartGuarantee->setNameWidth(labelWidth);
  m_tabThirdPartGuarantee->setMultiSel(true);

  for (int i = 0; i < 3; i++) {
    if (0 == i) {
      m_tabThirdPartGuarantee->addTab(
          NewStringTable::strFilterThirdPartGuarantee(i),
          CBondContainer::TPGAll);
    } else if (1 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("中债");
      item1.id = CBondContainer::TPGCBIC;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("中证");
      item2.id = CBondContainer::TPGCSCI;
      vctSub.push_back(item2);

      SFilterSubMenuItem item3;
      item3.name = tr("中投保");
      item3.id = CBondContainer::TPGIG;
      vctSub.push_back(item3);

      SFilterSubMenuItem item4;
      item4.name = tr("中合担保");
      item4.id = CBondContainer::TPGSinoguarantee;
      vctSub.push_back(item4);

      SFilterSubMenuItem item5;
      item5.name = tr("瀚华融资担保");
      item5.id = CBondContainer::TPGHanHuaGuarantee;
      vctSub.push_back(item5);
      m_tabThirdPartGuarantee->addTab(
          NewStringTable::strFilterThirdPartGuarantee(i),
          CBondContainer::TPGNational, "", &vctSub);
    } else if (2 == i) {
      std::vector<SFilterSubMenuItem> vctSub;
      SFilterSubMenuItem item1;
      item1.name = tr("重庆");
      item1.id = CBondContainer::TPGChongQing;
      vctSub.push_back(item1);

      SFilterSubMenuItem item2;
      item2.name = tr("江苏");
      item2.id = CBondContainer::TPGJiangSu;
      vctSub.push_back(item2);

      SFilterSubMenuItem item3;
      item3.name = tr("四川");
      item3.id = CBondContainer::TPGSiChuan;
      vctSub.push_back(item3);

      SFilterSubMenuItem item4;
      item4.name = tr("安徽");
      item4.id = CBondContainer::TPGAnHui;
      vctSub.push_back(item4);

      SFilterSubMenuItem item5;
      item5.name = tr("广东");
      item5.id = CBondContainer::TPGGuangDong;
      vctSub.push_back(item5);

      SFilterSubMenuItem item6;
      item6.name = tr("其他");
      item6.id = CBondContainer::TPGOthers;
      vctSub.push_back(item5);
      m_tabThirdPartGuarantee->addTab(
          NewStringTable::strFilterThirdPartGuarantee(i),
          CBondContainer::TPGRegional, "", &vctSub);
    }
  }

  connect(m_tabThirdPartGuarantee, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterButtonClick);
  layout->addWidget(m_tabThirdPartGuarantee);
}

void BestQuoteFilter::createFilterGuarantor(QBoxLayout* layout) {
  QHBoxLayout* hLayout = new QHBoxLayout();
  hLayout->setContentsMargins(0, 0, 0, 0);
  hLayout->setSpacing(gap);

  m_labelGuarantor = new QLabel(tr("担保人"), this);
  m_labelGuarantor->setStyleSheet(
      QString("padding-left: 4px;color:#%1; background-color:#%2;border:1px "
              "solid #%2;border-radius:2px")
          .arg(StyleMgr::instance().color("TitleWord").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("StaticTextBK").rgb(), 0, 16));
  m_labelGuarantor->setFixedSize(labelWidth - gap - 6, lineHeight);

  m_searchGuarantor = new KeySearchWidget(this, "SearchBackNormal2", "Hover",
                                          "TipsBorder", 0, true, 20, 9);
  BondFilterGuarantorSearchEngine* engine =
      new BondFilterGuarantorSearchEngine();
  engine->setFilterWnd(this);
  m_searchGuarantor->setAutoSelect(false);
  m_searchGuarantor->setAutoKillFocus(true);
  m_searchGuarantor->setEditFocusChangedClearText(false);
  m_searchGuarantor->setSearchEngine(engine);
  m_searchGuarantor->setFixedWidth(175);
  m_searchGuarantor->setFixedHeight(lineHeight);
  m_searchGuarantor->setResultDlgMinWidth(300);
  m_searchGuarantor->setResultDlgMaxHeight(20 * 8);
  m_searchGuarantor->setColumnsWidth(1, 280);
  m_searchGuarantor->setPromptText(tr(""));

  m_btnGuarantor = new SImageButton(this, "guiframe_filter_drop");
  m_btnGuarantor->setColor(NAME_COLOR("MainTitleBack"), NAME_COLOR("Hover"),
                           NAME_COLOR("Hover"), NAME_COLOR("MainTitleBack"));
  m_btnGuarantor->setFixedSize(lineHeight, lineHeight);

  m_panelGuarantor = new QWidget();
  m_panelGuarantor->setFixedSize(50, 24);
  m_panelGuarantor->setStyleSheet(
      QString("background-color:#%1;border: 1px solid #%2;")
          .arg(StyleMgr::instance().color("StaticTextBK").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("BorderNormal").rgb(), 0, 16));

  QHBoxLayout* hCalcLayout = new QHBoxLayout();
  hCalcLayout->setContentsMargins(2, 0, 2, 0);
  hCalcLayout->setSpacing(2);
  m_panelGuarantor->setLayout(hCalcLayout);

  m_calcGuarantor = new FilterLabel("1", m_panelGuarantor);
  m_calcGuarantor->setFixedSize(22, 22);
  m_calcGuarantor->setStyleSheet(
      QString(
          "padding-left: 2px; color:#%1; background-color:#%2; border: none;")
          .arg(StyleMgr::instance().color("Highlight").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("BackNormal").rgb(), 0, 16));
  hCalcLayout->addWidget(m_calcGuarantor);
  connect(m_calcGuarantor, &FilterLabel::clicked, this,
          &BestQuoteFilter::onGuarantorLabelClick);

  SImageButton* btnClear = new SImageButton(this, "widgets_action_clean");
  hCalcLayout->addWidget(btnClear);
  connect(btnClear, &SImageButton::clicked, this,
          &BestQuoteFilter::onBtnGuarantorClearClick);

  hLayout->addWidget(m_labelGuarantor);
  hLayout->addWidget(m_searchGuarantor);
  hLayout->addWidget(m_btnGuarantor);
  hLayout->addWidget(m_panelGuarantor);
  hLayout->addSpacerItem(
      new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding));
  layout->addLayout(hLayout);

  m_panelGuarantor->hide();

  connect(m_btnGuarantor, &SImageButton::clicked, this,
          &BestQuoteFilter::onGuarantorClicked);
  connect(m_searchIssuer, &KeySearchWidget::resultClear, this,
          &BestQuoteFilter::onEditGuarantorResultClear);
}

void BestQuoteFilter::createFilterIssuerRating(QBoxLayout* layout) {
  m_tabIssuerRating = new SFilterButton(this);
  m_tabIssuerRating->setName(NewStringTable::strFilterIssuerRating(-1));
  m_tabIssuerRating->setNameWidth(labelWidth);
  m_tabIssuerRating->setMultiSel(true);

  for (int i = 0; i < 5; i++) {
    m_tabIssuerRating->addTab(NewStringTable::strFilterIssuerRating(i));
  }

  connect(m_tabIssuerRating, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterIssuerRatingClick1);

  m_treeIssuerRating = new SFilterTree(this, false, false, "TabBackNormal",
                                       "BorderNormal", 20, 64);
  m_treeIssuerRating->setName("");
  m_treeIssuerRating->setDefaultString(
      NewStringTable::strFilterIssuerRating(5));
  m_treeIssuerRating->setNameWidth(0);
  m_treeIssuerRating->setLeftOffset(0);
  m_treeIssuerRating->setFixedWidth(82);
  m_treeIssuerRating->setDropFixedWidth(118);
  m_treeIssuerRating->setFixedHeight(lineHeight);
  m_treeIssuerRating->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  for (int i = 6; i < 9; ++i) {
    treeData.addChild(NewStringTable::strFilterIssuerRating(i),
                      QString::number(i));
  }

  m_treeIssuerRating->setTreeData(treeData);

  connect(m_treeIssuerRating, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterIssuerRatingClick2);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 0, 0);
  subLayout->addWidget(m_tabIssuerRating);
  subLayout->addWidget(m_treeIssuerRating);
  subLayout->addSpacerItem(
      new QSpacerItem(14, 20, QSizePolicy::Fixed, QSizePolicy::Fixed));
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterCBRRating(QBoxLayout* layout) {
  m_tabCBRRating = new SFilterButton(this);
  m_tabCBRRating->setName(NewStringTable::strFilterCBRRating(-1));
  m_tabCBRRating->setNameWidth(labelWidth);
  m_tabCBRRating->setMultiSel(true);

  for (int i = 0; i < 5; i++) {
    m_tabCBRRating->addTab(NewStringTable::strFilterCBRRating(i));
  }

  connect(m_tabCBRRating, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterCBRRatingClick1);

  m_treeCBRRating = new SFilterTree(this, false, false, "TabBackNormal",
                                    "BorderNormal", 20, 104);
  m_treeCBRRating->setName("");
  m_treeCBRRating->setDefaultString(NewStringTable::strFilterCBRRating(5));
  m_treeCBRRating->setNameWidth(0);
  m_treeCBRRating->setLeftOffset(0);
  m_treeCBRRating->setFixedWidth(82);
  m_treeCBRRating->setDropFixedWidth(118);
  m_treeCBRRating->setFixedHeight(lineHeight);
  m_treeCBRRating->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  for (int i = 6; i < 11; ++i) {
    treeData.addChild(NewStringTable::strFilterCBRRating(i),
                      QString::number(i));
  }

  m_treeCBRRating->setTreeData(treeData);

  connect(m_treeCBRRating, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterCBRRatingClick2);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 0, 0);
  subLayout->addWidget(m_tabCBRRating);
  subLayout->addWidget(m_treeCBRRating);
  subLayout->addSpacerItem(
      new QSpacerItem(1, 20, QSizePolicy::Fixed, QSizePolicy::Fixed));
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterBondRating(QBoxLayout* layout) {
  m_tabBondRating = new SFilterButton(this);
  m_tabBondRating->setName(NewStringTable::strFilterBondRating(-1));
  m_tabBondRating->setNameWidth(labelWidth);
  m_tabBondRating->setMultiSel(true);

  for (int i = 0; i < 5; i++) {
    m_tabBondRating->addTab(NewStringTable::strFilterBondRating(i));
  }

  connect(m_tabBondRating, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterBondRatingClick1);

  m_treeBondRating = new SFilterTree(this, false, false, "TabBackNormal",
                                     "BorderNormal", 20, 45);
  m_treeBondRating->setName("");
  m_treeBondRating->setDefaultString(NewStringTable::strFilterBondRating(5));
  m_treeBondRating->setNameWidth(0);
  m_treeBondRating->setLeftOffset(0);
  m_treeBondRating->setFixedWidth(82);
  m_treeBondRating->setDropFixedWidth(118);
  m_treeBondRating->setFixedHeight(lineHeight);
  m_treeBondRating->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  for (int i = 6; i < 8; ++i) {
    treeData.addChild(NewStringTable::strFilterBondRating(i),
                      QString::number(i));
  }

  m_treeBondRating->setTreeData(treeData);

  connect(m_treeBondRating, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterBondRatingClick2);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 0, 0);
  subLayout->addWidget(m_tabBondRating);
  subLayout->addWidget(m_treeBondRating);
  subLayout->addSpacerItem(
      new QSpacerItem(30, 20, QSizePolicy::Fixed, QSizePolicy::Fixed));
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterCDCRating(QBoxLayout* layout) {
  m_tabCDCRating = new SFilterButton(this);
  m_tabCDCRating->setName(NewStringTable::strFilterCDCRating(-1));
  m_tabCDCRating->setNameWidth(labelWidth);
  m_tabCDCRating->setMultiSel(true);

  for (int i = 0; i < 5; i++) {
    m_tabCDCRating->addTab(NewStringTable::strFilterCDCRating(i));
  }

  connect(m_tabCDCRating, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterCDCRatingClick1);

  m_treeCDCRating = new SFilterTree(this, false, false, "TabBackNormal",
                                    "BorderNormal", 20, 84);
  m_treeCDCRating->setName("");
  m_treeCDCRating->setDefaultString(NewStringTable::strFilterCDCRating(5));
  m_treeCDCRating->setNameWidth(0);
  m_treeCDCRating->setLeftOffset(0);
  m_treeCDCRating->setFixedWidth(82);
  m_treeCDCRating->setDropFixedWidth(118);
  m_treeCDCRating->setFixedHeight(lineHeight);
  m_treeCDCRating->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  for (int i = 6; i < 10; ++i) {
    treeData.addChild(NewStringTable::strFilterCDCRating(i),
                      QString::number(i));
  }

  m_treeCDCRating->setTreeData(treeData);

  connect(m_treeCDCRating, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterCDCRatingClick2);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 0, 0);
  subLayout->addWidget(m_tabCDCRating);
  subLayout->addWidget(m_treeCDCRating);
  subLayout->addSpacerItem(
      new QSpacerItem(0, 20, QSizePolicy::Fixed, QSizePolicy::Fixed));
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterCSIRating(QBoxLayout* layout) {
  m_tabCSIRating = new SFilterButton(this);
  m_tabCSIRating->setName(NewStringTable::strFilterCSIRating(-1));
  m_tabCSIRating->setNameWidth(labelWidth);
  m_tabCSIRating->setMultiSel(true);

  for (int i = 0; i < 5; i++) {
    m_tabCSIRating->addTab(NewStringTable::strFilterCSIRating(i));
  }

  connect(m_tabCSIRating, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterCSIRatingClick1);

  m_treeCSIRating = new SFilterTree(this, false, false, "TabBackNormal",
                                    "BorderNormal", 20, 64);
  m_treeCSIRating->setName("");
  m_treeCSIRating->setDefaultString(NewStringTable::strFilterCSIRating(5));
  m_treeCSIRating->setNameWidth(0);
  m_treeCSIRating->setLeftOffset(0);
  m_treeCSIRating->setFixedWidth(82);
  m_treeCSIRating->setDropFixedWidth(118);
  m_treeCSIRating->setFixedHeight(lineHeight);
  m_treeCSIRating->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  for (int i = 6; i < 9; ++i) {
    treeData.addChild(NewStringTable::strFilterCSIRating(i),
                      QString::number(i));
  }

  m_treeCSIRating->setTreeData(treeData);

  connect(m_treeCSIRating, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterCSIRatingClick2);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 0, 0);
  subLayout->addWidget(m_tabCSIRating);
  subLayout->addWidget(m_treeCSIRating);
  subLayout->addSpacerItem(
      new QSpacerItem(14, 20, QSizePolicy::Fixed, QSizePolicy::Fixed));
  layout->addLayout(subLayout);
}

void BestQuoteFilter::createFilterSubType(QBoxLayout* layout) {
  QHBoxLayout* hLayout = new QHBoxLayout();
  hLayout->setContentsMargins(0, 0, 0, 0);
  hLayout->setSpacing(gap);

  m_treeSubType = new SFilterTree(this);  // 细分
  m_treeSubType->setName(NewStringTable::strFilterSubType(-1));
  m_treeSubType->setDefaultString(NewStringTable::strFilterSubType(0));
  m_treeSubType->setNameWidth(labelWidth);
  m_treeSubType->setFixedHeight(lineHeight);
  m_treeSubType->setFixedWidth(labelWidth + 210);
  m_treeSubType->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  vector<CBondType>* pList = CBondTypeList::instance().GetBondTypeList();
  if (pList) {
    STreeData treeData;
    std::vector<CBondType>::iterator itor = pList->begin();
    for (; itor != pList->end(); itor++) {
      if (itor->m_Name_C.empty()) {
        continue;
      }

      STreeData data;
      data.m_szText = QString::fromLocal8Bit(itor->m_Name_C.c_str());
      data.m_szData = QString::fromLocal8Bit(itor->m_Code.c_str());

      vector<CBondType>* pSubList = itor->GetBondSubTypeList();
      if (pSubList) {
        vector<CBondType>::const_iterator subitor = pSubList->begin();
        for (; subitor != pSubList->end(); subitor++) {
          if (subitor->m_Name_C.empty()) {
            continue;
          }

          STreeData subdata;
          subdata.m_szText = QString::fromLocal8Bit(subitor->m_Name_C.c_str());
          subdata.m_szData = QString::fromLocal8Bit(subitor->m_Code.c_str());
          data.addChild(subdata);
        }
      }

      treeData.addChild(data);
    }

    m_treeSubType->setTreeData(treeData);
  }

  connect(m_treeSubType, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterButtonClick);

  hLayout->addWidget(m_treeSubType);
  hLayout->addSpacerItem(
      new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding));
  layout->addLayout(hLayout);
}

void BestQuoteFilter::createFilterSector(QBoxLayout* layout) {
  QHBoxLayout* hLayout = new QHBoxLayout();
  hLayout->setContentsMargins(0, 0, 0, 0);
  hLayout->setSpacing(gap);

  m_treeSector = new SFilterTree(this);  // 行业
  m_treeSector->setName(NewStringTable::strFilterSector(-1));
  m_treeSector->setDefaultString(NewStringTable::strFilterSector(0));
  m_treeSector->setNameWidth(labelWidth);
  m_treeSector->setFixedHeight(lineHeight);
  m_treeSector->setFixedWidth(labelWidth + 210);
  m_treeSector->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  std::map<std::string, QBSWSECTORINFO> stlIndustry;
  std::map<std::string, QBSWSECTORINFO>::iterator secitor;
  stlIndustry = CQBSwSectorInfo::instance2021().GetAllSwSectorInfo();
  for (auto& it : stlIndustry) {  // 一级行业
    QBSWSECTORINFO& st1 = it.second;
    if (st1.SW_Level == '1') {
      STreeData data;
      data.m_szText = QString::fromLocal8Bit(st1.SW_Name);
      data.m_szData = QString::fromLocal8Bit(st1.SW_Internal_Code);
      for (auto& it2 : stlIndustry) {  // 二级行业
        QBSWSECTORINFO& st2 = it2.second;
        if (st2.SW_Level == '2' &&
            strcmp(st2.SW_Upper_Grade_Code, st1.SW_Internal_Code) == 0) {
          STreeData subdata;
          subdata.m_szText = QString::fromLocal8Bit(st2.SW_Name);
          subdata.m_szData = QString::fromLocal8Bit(st2.SW_Internal_Code);
          data.addChild(subdata);
        }
      }
      treeData.addChild(data);
    }
  }
  m_treeSector->setTreeData(treeData);

  connect(m_treeSector, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterButtonClick);

  hLayout->addWidget(m_treeSector);
  hLayout->addSpacerItem(
      new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding));
  layout->addLayout(hLayout);
}

void BestQuoteFilter::createFilterArea(QBoxLayout* layout) {
  QHBoxLayout* hLayout = new QHBoxLayout();
  hLayout->setContentsMargins(0, 0, 0, 0);
  hLayout->setSpacing(gap);

  m_treeArea = new SFilterTree(this);  // 地区
  m_treeArea->setName(NewStringTable::strFilterArea(-1));
  m_treeArea->setDefaultString(NewStringTable::strFilterArea(0));
  m_treeArea->setNameWidth(labelWidth);
  m_treeArea->setFixedHeight(lineHeight);
  m_treeArea->setFixedWidth(labelWidth + 210);
  m_treeArea->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  std::map<std::string, QBPROVINCEINFO> stlProvice;
  std::map<std::string, QBPROVINCEINFO>::iterator itor;
  stlProvice = CQBProvinceInfo::instance().GetAllProviceInfo();
  for (itor = stlProvice.begin(); itor != stlProvice.end(); itor++) {
    QBPROVINCEINFO& stProvince = itor->second;
    if (strcmp(stProvince.Area_Level, "PRN") != 0) continue;
    QString szText = QString::fromLocal8Bit(stProvince.Area_Name);
    QString szValue = QString::fromLocal8Bit(stProvince.Area_Code);
    treeData.addChild(szText, szValue);
  }
  m_treeArea->setTreeData(treeData);

  connect(m_treeArea, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterButtonClick);

  hLayout->addWidget(m_treeArea);
  hLayout->addSpacerItem(
      new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding));
  layout->addLayout(hLayout);
}

void BestQuoteFilter::createFilterYear(QBoxLayout* layout) {
  CBondContainer& bc = CBondContainer::instance();
  int nLastYear;
  nLastYear = bc.GetMaxIssueDate() / 10000;
  int nPreYear;
  nPreYear = bc.GetMinIssueDate() / 10000;

  m_tabYear = new SFilterButton(this);
  m_tabYear->setName(NewStringTable::strFilterYear(-1));
  m_tabYear->setNameWidth(labelWidth);
  m_tabYear->addTab(NewStringTable::strFilterYear(0));
  m_tabYear->setMultiSel(true);

  for (int i = nLastYear; i > nLastYear - 4; i--) {
    QString szText = QString("%1").arg(i);
    m_tabYear->addTab(szText, i);
  }

  connect(m_tabYear, &SFilterButton::tabSelected, this,
          &BestQuoteFilter::onFilterYearClick1);

  m_treeYear = new SFilterTree(this, false, false, "TabBackNormal",
                               "BorderNormal", 20, 104);
  m_treeYear->setName("");
  m_treeYear->setDefaultString(NewStringTable::strFilterYear(1));
  m_treeYear->setNameWidth(0);
  m_treeYear->setLeftOffset(0);
  m_treeYear->setFixedWidth(82);
  m_treeYear->setDropFixedWidth(118);
  m_treeYear->setFixedHeight(lineHeight);
  m_treeYear->setComboStyleSheet(
      QString("QComboBox{border:1px solid #%1;}")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16));

  STreeData treeData;
  for (int i = nLastYear - 4; i >= nPreYear; i--) {
    QString szText = QString("%1").arg(i);
    QString szValue = szText;
    treeData.addChild(szText, szValue);
  }
  m_treeYear->setTreeData(treeData);

  connect(m_treeYear, &SFilterTree::filterChanged, this,
          &BestQuoteFilter::onFilterYearClick2);

  QHBoxLayout* subLayout = new QHBoxLayout(this);
  subLayout->setContentsMargins(0, 0, 0, 0);
  subLayout->addWidget(m_tabYear);
  subLayout->addWidget(m_treeYear);
  subLayout->addSpacerItem(
      new QSpacerItem(0, 20, QSizePolicy::Fixed, QSizePolicy::Fixed));
  layout->addLayout(subLayout);
}

namespace {
#define addFilterButton(pTab, strName, count, multi)                \
  pTab = new SFilterButton(this);                                   \
  pTab->setMultiSel(multi);                                         \
  pTab->setName(NewStringTable::strName(-1));                       \
  pTab->setNameWidth(labelWidth);                                   \
  for (int i = 0; i < count; i++) {                                 \
    pTab->addTab(NewStringTable::strName(i));                       \
  }                                                                 \
  if (NewStringTable::strName(-1).length() > 0) pTab->selectTab(0); \
  connect(pTab, &SFilterButton::tabSelected, this,                  \
          &BestQuoteFilter::onFilterButtonClick);                   \
  mainLayout->addWidget(pTab);
}  // namespace

void BestQuoteFilter::setupUi() {
  QVBoxLayout* mainLayout = new QVBoxLayout(this);
  mainLayout->setContentsMargins(gap, gap, gap, gap);
  mainLayout->setSpacing(gap);

  createFilterPrice1(mainLayout);

  mainLayout->addSpacing(lineHeight + gap);

  addFilterButton(m_tabSettlement, strFilterClearSpeed, 5, false);  // 清算速度
  createFilterQuoteType(mainLayout);  // 报价类型

  createFilterPrice2(mainLayout);
  mainLayout->addSpacing(lineHeight + gap);

  createFilterProduct1(mainLayout);
  createFilterProduct2(mainLayout);
  createFilterProduct3(mainLayout);
  createFilterProduct4(mainLayout);
  createFilterProduct5(mainLayout);

  addFilterButton(m_tabLocalBond, strFilterLocalBond, 3, false);  // 地方债
  createFilterLocalBondSpecial(mainLayout);  // 地方债专项
  createFilterLocalBondArea(mainLayout);     // 地方债地区
  createFilterNCD(mainLayout);               // NCD
  createFilterTerm(mainLayout);              // 期限
  createFilterIssuer(mainLayout);            // 发行人

  createFilterHot1(mainLayout);  // 热门概念
  createFilterHot2(mainLayout);
  createFilterHot3(mainLayout);
  createFilterHot4(mainLayout);
  createFilterHot5(mainLayout);

  addFilterButton(m_tabInvest, strFilterInvest, 5, false);       // 城投
  addFilterButton(m_tabPformType, strFilterPformType, 5, true);  // 城投层级
  createFilterMuniArea(mainLayout);                              // 城投地区

  createFilterGrade(mainLayout);  // 高收益债

  addFilterButton(m_tabBank, strFilterBank, 6, true);  // 银行业
  createFilterSector(mainLayout);                      // 行业

  addFilterButton(m_tabCorp, strFilterCorp, 5, true);  // 企业

  createFilterAssure(mainLayout);        // 担保
  createThirdPartGuarantee(mainLayout);  // 三方担保
  createFilterGuarantor(mainLayout);     // 担保人

  createFilterIssuerRating(mainLayout);  // 主体
  createFilterCBRRating(mainLayout);     // 中债资信

  addFilterButton(m_tabOutlook, strFilterOutlook, 5, true);  // 展望

  createFilterBondRating(mainLayout);  // 债项
  createFilterCDCRating(mainLayout);   // 中债隐含
  createFilterCSIRating(mainLayout);   // 中证隐含

  addFilterButton(m_tabAssetStatus, strFilterAssetStatus, 4, true);  // 发行
  addFilterButton(m_tabOptionType, strFilterOptionType, 5, true);    // 含权
  addFilterButton(m_tabPrincipayPayType, strFilterPrincipayPayType, 3,
                  true);                                     // 偿还方式
  addFilterButton(m_tabETSBond, strFilterETSBond, 5, true);  // 永续债
  addFilterButton(m_tabSubordinatedBond, strFilterSubordinatedBond, 3,
                  true);  // 次级债
  addFilterButton(m_tabListedVenues, strFilterListedVenues, 5,
                  true);                                       // 上市场所
  addFilterButton(m_tabRateType, strFilterParValue, 5, true);  // 利率方式
  addFilterButton(m_tabMarketMakeTarget, strFilterMarketMakeTarget, 5,
                  true);  // 做市标的

  createFilterYear(mainLayout);     // 发行年份
  createFilterArea(mainLayout);     // 地区
  createFilterSubType(mainLayout);  // 细分

  addFilterButton(m_tabBondLiquidity, strFilterBondLiquidity, 6,
                  true);  // 债券流动性
  addFilterButton(m_tabIssuerLiquidity, strFilterIssuerLiquidity, 6,
                  true);  // 主体流动性

  // addFilterButton(m_tabCommon, strFilterCommon, 12);//常用
  addFilterButton(m_tabCouponType, strFilterCouponType, 5, false);  // 票面

  mainLayout->addStretch();
}

void BestQuoteFilter::setIssuerSearchResult(const StringArray* pInfo,
                                            bool ctrl) {
  QString szKey = m_searchIssuer->getSearchKey();
  IssuerInfo* issuerInfo = (IssuerInfo*)pInfo;
  if (nullptr == issuerInfo) {
    m_vctIssuer.clear();
    updateShowAllStatus();
    return;
  }

  const char* code = issuerInfo->field((int)kIssuerInfo::Institution_Code);
  if (code) {
    auto it = m_setIssuer.find(code);
    if (it != m_setIssuer.end()) {
      return;
    }

    m_setIssuer.insert(code);
    m_vctIssuer.push_back(code);

    if (!ctrl) {
      updateShowAllStatus();
      return;
    }

    if (!m_ftvIssuer) {
      m_ftvIssuer = new FilterTableView();
      connect(m_ftvIssuer, &FilterTableView::filterRemove, this,
              &BestQuoteFilter::onFilterIssuerRemove);
    }

    std::vector<QString> vctContent = m_ftvIssuer->getContent();
    vctContent.push_back(QString::fromLocal8Bit(
        issuerInfo->field((int)kIssuerInfo::Full_Name_C)));
    m_ftvIssuer->setContent(vctContent);

    m_calcIssuer->setText(QString::number((int)vctContent.size()));

    m_searchIssuer->setSearchText(QString::fromLocal8Bit(issuerInfo->field(
                                      (int)kIssuerInfo::Full_Name_C)),
                                  true);
    m_searchIssuer->setEditFocus();
  }

  /*	BLHCONDITION blh;
          blh.nMatFlg = 1;
          m_filterCondition.stBlh = blh;
          m_filterCondition.nSearchType = searchResult_all;
          m_filterCondition.strSearch = szKey;*/

  updateShowAllStatus();

  if (m_searchIssuer) m_searchIssuer->setEditFocus();
  if (m_panelIssuer) m_panelIssuer->show();
}

void BestQuoteFilter::setGuarantorSearchResult(const StringArray* pInfo) {
  QString szKey = m_searchGuarantor->getSearchKey();
  IssuerInfo* issuerInfo = (IssuerInfo*)pInfo;
  const char* code = issuerInfo->field((int)kIssuerInfo::Institution_Code);
  if (code) {
    auto it = m_setGuarantor.find(code);
    if (it != m_setGuarantor.end()) {
      return;
    }

    m_setGuarantor.insert(code);
    m_vctGuarantor.push_back(code);

    if (!m_ftvGuarantor) {
      m_ftvGuarantor = new FilterTableView();
      connect(m_ftvGuarantor, &FilterTableView::filterRemove, this,
              &BestQuoteFilter::onFilterGuarantorRemove);
    }

    std::vector<QString> vctContent = m_ftvGuarantor->getContent();
    vctContent.push_back(QString::fromLocal8Bit(
        issuerInfo->field((int)kIssuerInfo::Full_Name_C)));
    m_ftvGuarantor->setContent(vctContent);

    m_calcGuarantor->setText(QString::number((int)vctContent.size()));

    m_searchGuarantor->setSearchText(QString::fromLocal8Bit(issuerInfo->field(
                                         (int)kIssuerInfo::Full_Name_C)),
                                     true);
    m_searchGuarantor->setEditFocus();
  }

  updateShowAllStatus();

  m_btnShowAll->setChecked(false);

  if (m_searchGuarantor) m_searchGuarantor->setEditFocus();
  if (m_panelGuarantor) m_panelGuarantor->show();
}

void BestQuoteFilter::updateShowAllStatus() {
  static BLHCONDITION blhDefault;
  blhDefault.nMatFlg = 1;
  blhDefault.nHasFlg = 1;
  BLHCONDITION blh;
  getBLH(blh);
  if (blh == blhDefault)
    m_btnShowAll->setChecked(true);
  else
    m_btnShowAll->setChecked(false);

  m_filterCondition.stBlh = blh;
  emit filterChange();
}

void BestQuoteFilter::onFilterButtonClick() { updateShowAllStatus(); }

void BestQuoteFilter::onFilterProduct1Click(int index) {
  if (0 == index) {
    m_tabProduct2->clearSelect();
    m_tabProduct3->clearSelect();
    m_tabProduct4->clearSelect();
    m_tabProduct5->clearSelect();
    enableRateGroup();
    enableCreditGroup();
    enableNCDGroup();
  } else if (1 == index) {
    if (!m_tabProduct1->isSelected(1)) {
      m_tabProduct1->changeSelect(0, false);
      m_tabProduct2->clearSelect();
      enableRateGroup();

      std::vector<int> vctSelect;
      m_tabProduct2->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct3->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct4->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct5->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct1->changeSelect(0, true);
    } else {
      m_tabProduct1->changeSelect(0, false);
      m_tabProduct2->selectAllTabs();
      disableRateGroup();
    }
  } else if (2 == index) {
    if (!m_tabProduct1->isSelected(2)) {
      m_tabProduct1->changeSelect(0, false);
      m_tabProduct3->clearSelect();
      m_tabProduct4->clearSelect();
      enableCreditGroup();

      for (int i = 0; i < 3; ++i) {
        m_tabProduct5->changeSelect(i, false);
      }

      std::vector<int> vctSelect;
      m_tabProduct2->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct3->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct4->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct5->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct1->changeSelect(0, true);
    } else {
      m_tabProduct1->changeSelect(0, false);
      m_tabProduct3->selectAllTabs();
      m_tabProduct4->selectAllTabs();
      for (int i = 0; i < 3; ++i) {
        m_tabProduct5->changeSelect(i, true);
      }
      disableCreditGroup();
    }
  } else if (3 == index) {
    if (!m_tabProduct1->isSelected(3)) {
      m_tabProduct1->changeSelect(0, false);
      m_tabProduct5->changeSelect(3, false);
      enableNCDGroup();

      std::vector<int> vctSelect;
      m_tabProduct2->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct3->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct4->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct5->getSelTab(vctSelect, true);
      if (vctSelect.size() > 0) return;
      m_tabProduct1->changeSelect(0, true);
    } else {
      m_tabProduct1->changeSelect(0, false);
      m_tabProduct5->changeSelect(3, true);
      disableNCDGroup();
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterProduct2Click(int index) {
  if (m_tabProduct2->isSelected(index, true)) {
    m_tabProduct1->changeSelect(0, false);
    disableRateGroup();
  } else {
    std::vector<int> vctSelect;
    m_tabProduct2->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct3->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct4->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct5->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;

    m_tabProduct1->changeSelect(0, true);
    enableRateGroup();
    enableCreditGroup();
    enableNCDGroup();
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterProduct3Click(int index) {
  if (m_tabProduct3->isSelected(index, true)) {
    m_tabProduct1->changeSelect(0, false);
    disableCreditGroup();
  } else {
    std::vector<int> vctSelect;
    m_tabProduct2->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct3->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct4->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct5->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;

    m_tabProduct1->changeSelect(0, true);
    enableRateGroup();
    enableCreditGroup();
    enableNCDGroup();
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterProduct4Click(int index) {
  if (m_tabProduct4->isSelected(index, true)) {
    m_tabProduct1->changeSelect(0, false);
    disableCreditGroup();
  } else {
    std::vector<int> vctSelect;
    m_tabProduct2->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct3->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct4->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct5->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;

    m_tabProduct1->changeSelect(0, true);
    enableRateGroup();
    enableCreditGroup();
    enableNCDGroup();
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterProduct5Click(int index) {
  if (m_tabProduct5->isSelected(index, true)) {
    m_tabProduct1->changeSelect(0, false);

    if (3 == index) {
      m_tabProduct1->changeSelect(3, true);
      disableNCDGroup();
    } else {
      disableCreditGroup();
    }
  } else {
    if (3 == index) {
      m_tabProduct1->changeSelect(3, false);
    }

    std::vector<int> vctSelect;
    m_tabProduct2->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct3->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct4->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabProduct5->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;

    m_tabProduct1->changeSelect(0, true);
    enableRateGroup();
    enableCreditGroup();
    enableNCDGroup();
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterLocalBondAreaClick1(int index) {
  std::vector<int> vctSelect;
  m_tabLocalBondArea->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeLocalBondArea->getSelectItemData();

  if (0 == index && 1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
    m_treeLocalBondArea->clearSelect();
  } else if ((int)lstSel.size() > 0) {
    if (m_tabLocalBondArea->isSelected(0)) {
      m_tabLocalBondArea->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterLocalBondAreaClick2() {
  std::vector<int> vctSelect;
  m_tabLocalBondArea->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeLocalBondArea->getSelectItemData();

  if (lstSel.isEmpty()) {
    if (vctSelect.empty()) {
      m_tabLocalBondArea->changeSelect(0, true);
    }
  } else {
    if (1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
      m_tabLocalBondArea->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterNCDClick1(int index) {
  std::vector<int> vctSelect;
  m_tabBondNCD->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeNCD->getSelectItemData();

  if (0 == index && 1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
    m_treeNCD->clearSelect();
  } else if ((int)lstSel.size() > 0) {
    if (m_tabBondNCD->isSelected(0)) {
      m_tabBondNCD->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterNCDClick2() {
  std::vector<int> vctSelect;
  m_tabBondNCD->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeNCD->getSelectItemData();

  if (lstSel.isEmpty()) {
    if (vctSelect.empty()) {
      m_tabBondNCD->changeSelect(0, true);
    }
  } else {
    if (1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
      m_tabBondNCD->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterTermClick() {
  m_edtTermBegin->clear();
  m_edtTermEnd->clear();

  updateShowAllStatus();
}

void BestQuoteFilter::onTermFilterButtonClick() {
  m_fltTerm->clearSelect();

  updateShowAllStatus();
}

void BestQuoteFilter::onTermClicked() {
  m_bShowDY = !m_bShowDY;
  m_edtTermBegin->setReadOnly(!m_bShowDY);
  m_edtTermEnd->setReadOnly(!m_bShowDY);
  m_edtTermBegin->setText("");
  m_edtTermEnd->setText("");

  if (m_bShowDY) {
    m_btnTerm->setImgId("guiframe_daymonthyear");
    m_btnTerm->setToolTip(
        tr("Y=年, M=月, D=天\n 例: 1.5~5Y\n      6M~12M\n      10D~365D"));
    m_edtTermBegin->setPlaceholderText("");
    m_edtTermEnd->setPlaceholderText("");
  } else {
    m_btnTerm->setImgId("guiframe_calendar");
    m_btnTerm->setToolTip("");
    m_edtTermBegin->setPlaceholderText(tr("选择到期日"));
    m_edtTermEnd->setPlaceholderText(tr("选择到期日"));
  }
}

void BestQuoteFilter::onIssuerClicked() { showIssuerFilter(m_btnIssuer); }

void BestQuoteFilter::onFilterIssuerClick() {
  const QStringList& lstSel = m_treeIssuer->getSelectItemData();

  if (0 == (int)lstSel.size()) {
    m_vctIssuer.clear();
    m_setIssuer.clear();
    m_panelIssuer->hide();
    m_treeIssuer->hide();

    if (!m_ftvIssuer) {
      m_ftvIssuer = new FilterTableView();
      connect(m_ftvIssuer, &FilterTableView::filterRemove, this,
              &BestQuoteFilter::onFilterIssuerRemove);
    }

    std::vector<QString> vctContent = m_ftvIssuer->getContent();
    vctContent.clear();
    m_calcIssuer->setText(QString::number((int)m_vctIssuer.size()));

    updateShowAllStatus();
    return;
  } else {
    m_panelIssuer->show();
  }

  if (!m_ftvIssuer) {
    m_ftvIssuer = new FilterTableView();
    connect(m_ftvIssuer, &FilterTableView::filterRemove, this,
            &BestQuoteFilter::onFilterIssuerRemove);
  }

  std::vector<QString> vctContent = m_ftvIssuer->getContent();
  vctContent.clear();
  m_vctIssuer.clear();
  m_setIssuer.clear();

  for (auto it : lstSel) {
    const IssuerInfo* pIssuer = CQBIssuerInfo::instance().GetIssuerInfoByIndex(
        atoi(it.toLatin1().data()));
    if (!pIssuer) continue;

    m_vctIssuer.push_back(pIssuer->field((int)kIssuerInfo::Institution_Code));
    m_setIssuer.insert(pIssuer->field((int)kIssuerInfo::Institution_Code));
    vctContent.push_back(
        QString::fromLocal8Bit(pIssuer->field((int)kIssuerInfo::Full_Name_C)));
  }

  m_ftvIssuer->setContent(vctContent);
  m_calcIssuer->setText(QString::number((int)vctContent.size()));

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterIssuerIndexClick(int index) {
  if (!m_treeIssuer) {
    return;
  }

  m_treeIssuer->clearTreeData();
  STreeData treeData;
  CQBIssuerInfo& IInfo = CQBIssuerInfo::instance();
  int issuerCount = IInfo.GetAllIssuerCount();
  int count = 0;

  char pstr[2] = {0};
  pstr[0] = 'A' + index;

  for (int i = 0; i < issuerCount; i++) {
    if (count >= 200) break;
    const IssuerInfo* pIssuer = IInfo.GetIssuerInfoByIndex(i);
    if (!pIssuer) continue;

    bool found = false;

    do {
      qb::PinyinManager& pyMgr = qb::PinyinManager::instance();
      std::string sJianpin, sQuanpin;
      pyMgr.GetPinyin(pIssuer->field((int)kIssuerInfo::Full_Name_C), sJianpin,
                      sQuanpin);

      found = (sJianpin.length() > 0 && sJianpin[0] == pstr[0]);  // 简拼匹配
      if (found) {
        break;
      }

      found = (sQuanpin.length() > 0 && sQuanpin[0] == pstr[0]);  // 全拼匹配
      if (found) {
        break;
      }
    } while (0);

    if (found) {
      bool check = false;
      auto it =
          m_setIssuer.find(pIssuer->field((int)kIssuerInfo::Institution_Code));
      if (it != m_setIssuer.end()) {
        check = true;
      }

      treeData.addChild(
          QString::fromLocal8Bit(pIssuer->field((int)kIssuerInfo::Full_Name_C)),
          QString::number(i), check);
      count++;
    }
  }

  m_treeIssuer->setTreeData(treeData);
}

void BestQuoteFilter::onBtnIssuerClearClick() {
  m_vctIssuer.clear();
  m_setIssuer.clear();
  m_calcIssuer->setText(QString::number((int)m_vctIssuer.size()));
  m_panelIssuer->hide();
  m_searchIssuer->setSearchText("");
  onFilterIssuerIndexClick(0);

  updateShowAllStatus();
}

void BestQuoteFilter::onIssuerLabelClick() {
  if (!m_ftvIssuer) {
    m_ftvIssuer = new FilterTableView();
    connect(m_ftvIssuer, &FilterTableView::filterRemove, this,
            &BestQuoteFilter::onFilterIssuerRemove);
  }

  QRect rc = m_calcIssuer->rect();
  QPoint pt = m_calcIssuer->mapToGlobal(QPoint(rc.left(), rc.bottom()));
  m_ftvIssuer->setGeometry(pt.x(), pt.y(), m_ftvIssuer->width(),
                           m_ftvIssuer->height());

  m_ftvIssuer->show();
  m_ftvIssuer->activateWindow();
}

void BestQuoteFilter::onFilterIssuerRemove(int index) {
  if (index < 0 || index >= (int)m_vctIssuer.size()) {
    return;
  }

  std::string code(m_vctIssuer[index]);
  m_vctIssuer.erase(m_vctIssuer.begin() + index);
  auto it = m_setIssuer.find(code);
  if (it != m_setIssuer.end()) {
    m_setIssuer.erase(it);
  }

  m_calcIssuer->setText(QString::number((int)m_vctIssuer.size()));

  if (0 == (int)m_vctIssuer.size()) {
    m_setIssuer.clear();
    onFilterIssuerIndexClick(0);
    m_ftvIssuer->hide();
    m_panelIssuer->hide();
    m_searchIssuer->setSearchText("");
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onEditIssuerResultClear() {
  m_searchIssuer->setSearchText("");
}

void BestQuoteFilter::onGuarantorClicked() {
  showGuarantorFilter(m_btnGuarantor);
}

void BestQuoteFilter::onFilterGuarantorClick() {
  const QStringList& lstSel = m_treeGuarantor->getSelectItemData();
  if (0 == (int)lstSel.size()) {
    m_vctGuarantor.clear();
    m_setGuarantor.clear();
    m_panelGuarantor->hide();
    m_treeGuarantor->hide();

    if (!m_ftvGuarantor) {
      m_ftvGuarantor = new FilterTableView();
      connect(m_ftvGuarantor, &FilterTableView::filterRemove, this,
              &BestQuoteFilter::onFilterGuarantorRemove);
    }

    std::vector<QString> vctContent = m_ftvGuarantor->getContent();
    vctContent.clear();
    m_calcGuarantor->setText(QString::number((int)m_vctGuarantor.size()));

    updateShowAllStatus();
    return;
  } else {
    m_panelGuarantor->show();
  }

  if (!m_ftvGuarantor) {
    m_ftvGuarantor = new FilterTableView();
    connect(m_ftvGuarantor, &FilterTableView::filterRemove, this,
            &BestQuoteFilter::onFilterGuarantorRemove);
  }

  std::vector<QString> vctContent = m_ftvGuarantor->getContent();
  vctContent.clear();
  m_vctGuarantor.clear();
  m_setGuarantor.clear();

  for (auto it : lstSel) {
    const IssuerInfo* pIssuer =
        CQBIssuerInfo::GuarantorInstitution().GetIssuerInfoByIndex(
            atoi(it.toLatin1().data()));
    if (!pIssuer) continue;

    m_vctGuarantor.push_back(
        pIssuer->field((int)kIssuerInfo::Institution_Code));
    m_setGuarantor.insert(pIssuer->field((int)kIssuerInfo::Institution_Code));
    vctContent.push_back(
        QString::fromLocal8Bit(pIssuer->field((int)kIssuerInfo::Full_Name_C)));
  }

  m_ftvGuarantor->setContent(vctContent);
  m_calcGuarantor->setText(QString::number((int)vctContent.size()));

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterGuarantorIndexClick(int index) {
  m_treeGuarantor->clearTreeData();
  STreeData treeData;
  CQBIssuerInfo& IInfo = CQBIssuerInfo::GuarantorInstitution();
  int issuerCount = IInfo.GetAllIssuerCount();
  int count = 0;

  char pstr[2] = {0};
  pstr[0] = 'A' + index;

  for (int i = 0; i < issuerCount; i++) {
    if (count >= 200) break;
    const IssuerInfo* pIssuer = IInfo.GetIssuerInfoByIndex(i);
    if (!pIssuer) continue;

    bool found = false;

    do {
      qb::PinyinManager& pyMgr = qb::PinyinManager::instance();
      std::string sJianpin, sQuanpin;
      pyMgr.GetPinyin(pIssuer->field((int)kIssuerInfo::Full_Name_C), sJianpin,
                      sQuanpin);

      found = (sJianpin.length() > 0 && sJianpin[0] == pstr[0]);  // 简拼匹配
      if (found) {
        break;
      }

      found = (sQuanpin.length() > 0 && sQuanpin[0] == pstr[0]);  // 全拼匹配
      if (found) {
        break;
      }
    } while (0);

    if (found) {
      bool check = false;
      auto it = m_setGuarantor.find(
          pIssuer->field((int)kIssuerInfo::Institution_Code));
      if (it != m_setGuarantor.end()) {
        check = true;
      }

      treeData.addChild(
          QString::fromLocal8Bit(pIssuer->field((int)kIssuerInfo::Full_Name_C)),
          QString::number(i), check);
      count++;
    }
  }

  m_treeGuarantor->setTreeData(treeData);
}

void BestQuoteFilter::onBtnGuarantorClearClick() {
  m_vctGuarantor.clear();
  m_setGuarantor.clear();
  m_calcGuarantor->setText(QString::number((int)m_vctGuarantor.size()));
  m_panelGuarantor->hide();
  m_searchGuarantor->setSearchText("");
  onFilterGuarantorIndexClick(0);

  updateShowAllStatus();
}

void BestQuoteFilter::onGuarantorLabelClick() {
  if (!m_ftvGuarantor) {
    m_ftvGuarantor = new FilterTableView();
    connect(m_ftvGuarantor, &FilterTableView::filterRemove, this,
            &BestQuoteFilter::onFilterGuarantorRemove);
  }

  QRect rc = m_calcGuarantor->rect();
  QPoint pt = m_calcGuarantor->mapToGlobal(QPoint(rc.left(), rc.bottom()));
  m_ftvGuarantor->setGeometry(pt.x(), pt.y(), m_ftvGuarantor->width(),
                              m_ftvGuarantor->height());

  m_ftvGuarantor->show();
  m_ftvGuarantor->activateWindow();
}

void BestQuoteFilter::onFilterGuarantorRemove(int index) {
  if (index < 0 || index >= (int)m_vctGuarantor.size()) {
    return;
  }

  std::string code(m_vctGuarantor[index]);
  m_vctGuarantor.erase(m_vctGuarantor.begin() + index);
  auto it = m_setGuarantor.find(code);
  if (it != m_setGuarantor.end()) {
    m_setGuarantor.erase(it);
  }

  m_calcGuarantor->setText(QString::number((int)m_vctGuarantor.size()));

  if (0 == (int)m_vctGuarantor.size()) {
    m_setIssuer.clear();
    onFilterIssuerIndexClick(0);
    m_ftvGuarantor->hide();
    m_panelGuarantor->hide();
    m_searchGuarantor->setSearchText("");
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onEditGuarantorResultClear() {
  m_searchGuarantor->setSearchText("");
}

void BestQuoteFilter::onEditTermBeginClicked() {
  if (m_bShowDY) {
    return;
  }

  m_bBeginCalendar = true;
  m_bEndCalendar = false;
  showTermCalendar(m_edtTermBegin);
}

void BestQuoteFilter::onEditTermEndClicked() {
  if (m_bShowDY) {
    return;
  }

  m_bBeginCalendar = false;
  m_bEndCalendar = true;
  showTermCalendar(m_edtTermEnd);
}

void BestQuoteFilter::onFilterCalendarClicked(const QDate& date) {
  if (m_bBeginCalendar) {
    m_edtTermBegin->setText(date.toString("yyyyMMdd"));
  }
  if (m_bEndCalendar) {
    m_edtTermEnd->setText(date.toString("yyyyMMdd"));
  }

  m_bBeginCalendar = false;
  m_bEndCalendar = false;
  m_termCalendar->hide();
}

void BestQuoteFilter::onFilterHot1Click(int index) {
  if (0 == index) {
    m_tabHot2->clearSelect();
    m_tabHot3->clearSelect();
    m_tabHot4->clearSelect();
    m_tabHot5->clearSelect();
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterHot2Click(int index) {
  if (m_tabHot2->isSelected(index, true)) {
    m_tabHot1->changeSelect(0, false);
  } else {
    std::vector<int> vctSelect;
    m_tabHot2->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot3->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot4->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot5->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;

    m_tabHot1->changeSelect(0, true);
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterHot3Click(int index) {
  if (m_tabHot3->isSelected(index, true)) {
    m_tabHot1->changeSelect(0, false);
  } else {
    std::vector<int> vctSelect;
    m_tabHot2->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot3->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot4->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot5->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;

    m_tabHot1->changeSelect(0, true);
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterHot4Click(int index) {
  if (m_tabHot4->isSelected(index, true)) {
    m_tabHot1->changeSelect(0, false);
  } else {
    std::vector<int> vctSelect;
    m_tabHot2->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot3->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot4->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot5->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;

    m_tabHot1->changeSelect(0, true);
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterHot5Click(int index) {
  if (m_tabHot5->isSelected(index, true)) {
    m_tabHot1->changeSelect(0, false);
  } else {
    std::vector<int> vctSelect;
    m_tabHot2->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot3->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot4->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;
    m_tabHot5->getSelTab(vctSelect, true);
    if (vctSelect.size() > 0) return;

    m_tabHot1->changeSelect(0, true);
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterIssuerRatingClick1(int index) {
  std::vector<int> vctSelect;
  m_tabIssuerRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeIssuerRating->getSelectItemData();

  if (0 == index && 1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
    m_treeIssuerRating->clearSelect();
  } else if ((int)lstSel.size() > 0) {
    if (m_tabIssuerRating->isSelected(0)) {
      m_tabIssuerRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterIssuerRatingClick2() {
  std::vector<int> vctSelect;
  m_tabIssuerRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeIssuerRating->getSelectItemData();

  if (lstSel.isEmpty()) {
    if (vctSelect.empty()) {
      m_tabIssuerRating->changeSelect(0, true);
    }
  } else {
    if (1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
      m_tabIssuerRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterCBRRatingClick1(int index) {
  std::vector<int> vctSelect;
  m_tabCBRRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeCBRRating->getSelectItemData();

  if (0 == index && 1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
    m_treeCBRRating->clearSelect();
  } else if ((int)lstSel.size() > 0) {
    if (m_tabCBRRating->isSelected(0)) {
      m_tabCBRRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterCBRRatingClick2() {
  std::vector<int> vctSelect;
  m_tabCBRRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeCBRRating->getSelectItemData();

  if (lstSel.isEmpty()) {
    if (vctSelect.empty()) {
      m_tabCBRRating->changeSelect(0, true);
    }
  } else {
    if (1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
      m_tabCBRRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterBondRatingClick1(int index) {
  std::vector<int> vctSelect;
  m_tabBondRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeBondRating->getSelectItemData();

  if (0 == index && 1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
    m_treeBondRating->clearSelect();
  } else if ((int)lstSel.size() > 0) {
    if (m_tabBondRating->isSelected(0)) {
      m_tabBondRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterBondRatingClick2() {
  std::vector<int> vctSelect;
  m_tabBondRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeBondRating->getSelectItemData();

  if (lstSel.isEmpty()) {
    if (vctSelect.empty()) {
      m_tabBondRating->changeSelect(0, true);
    }
  } else {
    if (1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
      m_tabBondRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterCDCRatingClick1(int index) {
  std::vector<int> vctSelect;
  m_tabCDCRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeCDCRating->getSelectItemData();

  if (0 == index && 1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
    m_treeCDCRating->clearSelect();
  } else if ((int)lstSel.size() > 0) {
    if (m_tabCDCRating->isSelected(0)) {
      m_tabCDCRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterCDCRatingClick2() {
  std::vector<int> vctSelect;
  m_tabCDCRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeCDCRating->getSelectItemData();

  if (lstSel.isEmpty()) {
    if (vctSelect.empty()) {
      m_tabCDCRating->changeSelect(0, true);
    }
  } else {
    if (1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
      m_tabCDCRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterCSIRatingClick1(int index) {
  std::vector<int> vctSelect;
  m_tabCSIRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeCSIRating->getSelectItemData();

  if (0 == index && 1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
    m_treeCSIRating->clearSelect();
  } else if ((int)lstSel.size() > 0) {
    if (m_tabCSIRating->isSelected(0)) {
      m_tabCSIRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterCSIRatingClick2() {
  std::vector<int> vctSelect;
  m_tabCSIRating->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeCSIRating->getSelectItemData();

  if (lstSel.isEmpty()) {
    if (vctSelect.empty()) {
      m_tabCSIRating->changeSelect(0, true);
    }
  } else {
    if (1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
      m_tabCSIRating->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterYearClick1(int index) {
  std::vector<int> vctSelect;
  m_tabYear->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeYear->getSelectItemData();

  if (0 == index && 1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
    m_treeYear->clearSelect();
  } else if ((int)lstSel.size() > 0) {
    if (m_tabYear->isSelected(0)) {
      m_tabYear->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onFilterYearClick2() {
  std::vector<int> vctSelect;
  m_tabYear->getSelTab(vctSelect, true);
  const QStringList& lstSel = m_treeYear->getSelectItemData();

  if (lstSel.isEmpty()) {
    if (vctSelect.empty()) {
      m_tabYear->changeSelect(0, true);
    }
  } else {
    if (1 == (int)vctSelect.size() && 0 == vctSelect[0]) {
      m_tabYear->changeSelect(0, false);
    }
  }

  updateShowAllStatus();
}

void BestQuoteFilter::onShowAll() {
  static BLHCONDITION blhDefault;
  blhDefault.nMatFlg = 1;
  blhDefault.nHasFlg = 1;
  m_filterCondition.stBlh = blhDefault;

  resetControl();
  emit filterChange();
}

void BestQuoteFilter::onCheckChange(int id) {
  switch (id) {
    case id_chk_valid:
      if (m_chkValid->isSelected()) {
        m_chkBothValid->setSelectState(Qt::Unchecked);
        m_chkBidValid->setSelectState(Qt::Unchecked);
        m_chkOfrValid->setSelectState(Qt::Unchecked);
      }
      break;
    case id_chk_bothvalid:
      if (m_chkBothValid->isSelected()) {
        m_chkValid->setSelectState(Qt::Unchecked);
        m_chkBidValid->setSelectState(Qt::Unchecked);
        m_chkOfrValid->setSelectState(Qt::Unchecked);
      } else {
        m_chkValid->setSelectState(Qt::Checked);
        m_chkBidValid->setSelectState(Qt::Unchecked);
        m_chkOfrValid->setSelectState(Qt::Unchecked);
      }
      break;
    case id_chk_bidvalid:
      if (m_chkBidValid->isSelected()) {
        m_chkValid->setSelectState(Qt::Unchecked);
        m_chkBothValid->setSelectState(Qt::Unchecked);
        m_chkOfrValid->setSelectState(Qt::Unchecked);
      } else {
        m_chkValid->setSelectState(Qt::Checked);
        m_chkBothValid->setSelectState(Qt::Unchecked);
        m_chkOfrValid->setSelectState(Qt::Unchecked);
      }
      break;
    case id_chk_ofrvalid:
      if (m_chkOfrValid->isSelected()) {
        m_chkValid->setSelectState(Qt::Unchecked);
        m_chkBidValid->setSelectState(Qt::Unchecked);
        m_chkBothValid->setSelectState(Qt::Unchecked);
      } else {
        m_chkValid->setSelectState(Qt::Checked);
        m_chkBidValid->setSelectState(Qt::Unchecked);
        m_chkBothValid->setSelectState(Qt::Unchecked);
      }
      break;
    default:
      break;
  }
  updateShowAllStatus();
}

void BestQuoteFilter::onRadioStateChanged(int index) {
  if (0 == index) {
    if (m_rdoYield->isSelected()) {
      m_rdoPrice->setSelectState(Qt::Unchecked);
    }
  } else if (1 == index) {
    if (m_rdoPrice->isSelected()) {
      m_rdoYield->setSelectState(Qt::Unchecked);
    }
  }

  // Bid/Ofr:
  m_edtBid->setPlaceholderText((0 == index) ? "%" : "");
  m_edtBid2->setPlaceholderText((0 == index) ? "%" : "");
  m_edtOfr->setPlaceholderText((0 == index) ? "%" : "");
  m_edtOfr2->setPlaceholderText((0 == index) ? "%" : "");

  // Bid - 中债:
  m_edtBidCdc->setPlaceholderText((0 == index) ? "BP" : "");
  m_edtBidCdc2->setPlaceholderText((0 == index) ? "BP" : "");

  // 中债 - Ofr:
  m_edtCdcOfr->setPlaceholderText((0 == index) ? "BP" : "");
  m_edtCdcOfr2->setPlaceholderText((0 == index) ? "BP" : "");

  // Bid–Ofr : BP
  m_edtBidOfr->setPlaceholderText((0 == index) ? "BP" : "");
  m_edtBidOfr2->setPlaceholderText((0 == index) ? "BP" : "");

  // 中债估值
  m_edtCdcValue->setPlaceholderText((0 == index) ? "%" : "");
  m_edtCdcValue2->setPlaceholderText((0 == index) ? "%" : "");
}

void BestQuoteFilter::resizeEvent(QResizeEvent* event) {
  QRect rc = rect();
  if (m_rect.width() != rc.width()) {
    m_rect = rc;
    int w = labelWidth + (rc.width() - 400) / 2;
    m_tabProduct1->setNameWidth(w);
    m_tabProduct2->setNameWidth(w);
    m_tabProduct3->setNameWidth(w);
    m_tabProduct4->setNameWidth(w);
    m_tabProduct5->setNameWidth(w);
    m_tabLocalBond->setNameWidth(w);
    m_tabLocalBondArea->setNameWidth(w);
    m_tabHot1->setNameWidth(w);
    m_tabHot2->setNameWidth(w);
    m_tabHot3->setNameWidth(w);
    m_tabHot4->setNameWidth(w);
    m_tabHot5->setNameWidth(w);
    m_tabBank->setNameWidth(w);
    //	m_tabCommon->setNameWidth(w);
    m_tabSettlement->setNameWidth(w);
    m_tabQuoteType->setNameWidth(w);
    m_tabETSBond->setNameWidth(w);
    m_tabSubordinatedBond->setNameWidth(w);
    m_tabListedVenues->setNameWidth(w);
    m_tabRateType->setNameWidth(w);
    m_tabMarketMakeTarget->setNameWidth(w);
    m_tabCorp->setNameWidth(w);
    m_tabInvest->setNameWidth(w);
    m_tabPformType->setNameWidth(w);
    m_tabIssuerRating->setNameWidth(w);
    m_tabBondRating->setNameWidth(w);
    m_tabCDCRating->setNameWidth(w);
    m_tabCSIRating->setNameWidth(w);
    m_tabCBRRating->setNameWidth(w);
    m_tabOutlook->setNameWidth(w);
    m_tabBondAssure->setNameWidth(w);
    m_tabThirdPartGuarantee->setNameWidth(w);
    m_tabBondNCD->setNameWidth(w);
    m_tabAssetStatus->setNameWidth(w);
    m_tabCouponType->setNameWidth(w);
    m_tabOptionType->setNameWidth(w);
    m_tabBondLiquidity->setNameWidth(w);
    m_tabIssuerLiquidity->setNameWidth(w);
    m_tabGrade->setNameWidth(w);
    m_tabYear->setNameWidth(w);
    m_tabPrincipayPayType->setNameWidth(w);
    m_treeLocalBondSpecial->setNameWidth(w);
    m_treeMuniArea->setNameWidth(w);
    m_treeSubType->setNameWidth(w);
    m_treeSector->setNameWidth(w);
    m_treeArea->setNameWidth(w);
    m_fltTerm->setNameWidth(w);
  }
}

void BestQuoteFilter::paintEvent(QPaintEvent* event) {
  QStylePainter painter(this);
  QRect rc = event->rect();
  painter.setPen(Qt::NoPen);
  QColor bkColor = NAME_COLOR("BasicPlate");
  painter.setBrush(bkColor);
  // QRect rc = rect();
  painter.drawRect(rc);

  QColor btnColor = NAME_COLOR("ButtonNormal");
  painter.setBrush(btnColor);
  SImage* img = ImgMgr::instance().image("guiframe_cmp_noless");
  SImage* imgTips = ImgMgr::instance().image(
      "widgets_circle_info", WidgetStatus::kNormal, devicePixelRatioF());

  if (imgTips && m_tabQuoteType) {
    QPoint pos = m_tabQuoteType->pos();
    QRect rc = m_tabQuoteType->rect();
    int left = pos.x() + rc.width() + gap;
    int top = pos.y() + rc.height() / 2 - 8;
    m_rcQuoteTypeTips.setRect(left, top, 16, 16);
    painter.drawImage(QPoint(left, top), *imgTips);
  }
  if (imgTips && m_tabProduct1) {
    QPoint pos = m_tabProduct1->pos();
    QRect rc = m_tabProduct1->rect();
    int left = pos.x() + rc.width() + gap;
    int top = pos.y() + rc.height() / 2 - 8;
    m_rcProductTips.setRect(left, top, 16, 16);
    painter.drawImage(QPoint(left, top), *imgTips);
  }
  if (img && m_edtVolBid) {
    QPoint pos = m_edtVolBid->pos();
    QRect rc = m_edtVolBid->rect();
    rc.moveTopLeft(pos);
    rc.setRight(pos.x() - gap);
    rc.setLeft(rc.right() - lineHeight);

    painter.drawRoundedRect(rc, 2, 2);
    int left = rc.center().x() - img->width() / 2;
    int top = pos.y() + (lineHeight - img->height()) / 2;
    painter.drawImage(QPoint(left, top), *img);
  }
  if (img && m_edtVolOfr) {
    QPoint pos = m_edtVolOfr->pos();
    QRect rc = m_edtVolOfr->rect();
    rc.moveTopLeft(pos);
    rc.setRight(pos.x() - gap);
    rc.setLeft(rc.right() - lineHeight);

    painter.drawRoundedRect(rc, 2, 2);
    int left = rc.center().x() - img->width() / 2;
    int top = pos.y() + (lineHeight - img->height()) / 2;
    painter.drawImage(QPoint(left, top), *img);
  }
  if (m_btnPriceFilter && m_tabProduct1 && m_btnShowAll && m_tabSettlement) {
    QPoint pos = m_btnPriceFilter->pos();
    QPoint pos2 = m_tabProduct1->pos();
    QRect rc = m_btnPriceFilter->rect();

    int y = (pos.y() + rc.height() + pos2.y()) / 2;
    int x0 = rect().left() + gap;
    int x1 = rect().right() - gap;

    QPen pen(NAME_COLOR("StaticTextBK"), 1);
    painter.setPen(pen);
    painter.drawLine(x0, y, x1, y);

    pos = m_btnShowAll->pos();
    pos2 = m_tabSettlement->pos();
    y = (pos.y() + rc.height() + pos2.y()) / 2;
    painter.drawLine(x0, y, x1, y);
  }
  if (imgTips && m_tabHot5) {
    QPoint pos = m_tabHot5->pos();
    QRect rc = m_tabHot5->rect();
    int left = pos.x() + rc.width() + gap;
    int top = pos.y() + rc.height() / 2 - 8;
    m_rcHotTips.setRect(left, top, 16, 16);
    painter.drawImage(QPoint(left, top), *imgTips);
  }
}

void BestQuoteFilter::mouseMoveEvent(QMouseEvent* event) {
  QFrame::mouseMoveEvent(event);

  QPoint mousePos = event->pos();

  if (m_rcQuoteTypeTips.contains(mousePos)) {
    dealTips(
        event,
        tr("1.实盘报价：价格和量无标识,报价被接受的,应当按照报价要素执行交易."
           "\n2.可部分执行报价：价格无标识,量标识\"p*\"或未明确交易数量,"
           "报价被接\n受的,应按照所报价格及不低于市场惯例的最小交易量执行交易."
           "\n3.意向性报价：价格标识\"*\",交易双方可对报价进行协商."));
  } else if (m_rcProductTips.contains(mousePos)) {
    dealTips(event, tr("根据利率债、信用债和NCD三大类,提供不同的筛选项"));
  } else if (m_rcHotTips.contains(mousePos)) {
    dealTips(event,
             tr("1.新上市：5个自然日内上市的债券.\n2."
                "不含假期：关于国务院未发布放假通知的年份，我司将按经验维护\n后"
                "2年的节假日，2年以外的仅考虑周末双休，仅供参考."));
  } else {
    QBTips::hideTip();
  }
}

void BestQuoteFilter::mousePressEvent(QMouseEvent* event) {
  QPoint mousePos = event->pos();

  if (m_rcQuoteTypeTips.contains(mousePos)) {
    dealTips(
        event,
        tr("1.实盘报价：价格和量无标识,报价被接受的,应当按照报价要素执行交易."
           "\n2.可部分执行报价：价格无标识,量标识\"p*\"或未明确交易数量,"
           "报价被接\n受的,应按照所报价格及不低于市场惯例的最小交易量执行交易."
           "\n3.意向性报价：价格标识\"*\",交易双方可对报价进行协商."));
  } else if (m_rcProductTips.contains(mousePos)) {
    dealTips(event, tr("根据利率债、信用债和NCD三大类,提供不同的筛选项"));
  } else if (m_rcHotTips.contains(mousePos)) {
    dealTips(event,
             tr("1.新上市：5个自然日内上市的债券.\n2."
                "不含假期：关于国务院未发布放假通知的年份，我司将按经验维护\n后"
                "2年的节假日，2年以外的仅考虑周末双休，仅供参考."));
  }

  QFrame::mousePressEvent(event);
}

void BestQuoteFilter::leaveEvent(QEvent* event) {
  QBTips::hideTip();

  QFrame::leaveEvent(event);
}

void BestQuoteFilter::dealTips(QMouseEvent* event, const QString& strTips) {
  std::vector<QBTipCustomItem> vctCustomItem;
  QBTipCustomItem item;
  item.row = 0;
  item.col = 1;
  item.clrNormal = NAME_COLOR("TextNormal");
  vctCustomItem.push_back(item);
  QBTips::showText(event->screenPos().toPoint(), strTips, this, &vctCustomItem);
}

void BestQuoteFilter::showTermCalendar(SLineEdit* edit) {
  if (!m_termCalendar) {
    m_termCalendar = new SCalendar();
    m_termCalendar->setFixedSize(264, 306);
    connect(m_termCalendar, &QCalendarWidget::clicked, this,
            &BestQuoteFilter::onFilterCalendarClicked);
  }

  if (!m_termCalendar->isVisible()) {
    QRect rc = edit->rect();
    QPoint pt = edit->mapToGlobal(
        QPoint(rc.left(), rc.bottom() - m_termCalendar->height() / 2));

    m_termCalendar->setGeometry(pt.x(), pt.y(), m_termCalendar->width(),
                                m_termCalendar->height());
    m_termCalendar->setSelectedDate(QDate::currentDate());
    m_termCalendar->setStart(QDate::currentDate());
    m_termCalendar->setEnd(QDate::currentDate());

    m_termCalendar->active();
    m_termCalendar->show();
  }
}

void BestQuoteFilter::showIssuerFilter(SImageButton* btn) {
  if (!m_treeIssuer) {
    m_treeIssuer = new STreeComboWidget(nullptr, false, true, 20, 212);
    m_treeIssuer->setWindowFlags(m_treeIssuer->windowFlags() |
                                 Qt::FramelessWindowHint);
    m_treeIssuer->setFixedWidth(248);
    m_treeIssuer->setFixedHeight(212);
    m_treeIssuer->setFocusPolicy(Qt::NoFocus);
    m_treeIssuer->showToolTip(200);
    m_treeIssuer->setAutoDisappear();

    connect(m_treeIssuer, &STreeComboWidget::itemSelectChanged, this,
            &BestQuoteFilter::onFilterIssuerClick);
    connect(m_treeIssuer, &STreeComboWidget::filterIndexSelectChanged, this,
            &BestQuoteFilter::onFilterIssuerIndexClick);

    onFilterIssuerIndexClick(0);
  }

  if (!m_treeIssuer->isVisible()) {
    QRect rc = btn->rect();
    QPoint pt = btn->mapToGlobal(QPoint(rc.left(), rc.bottom()));
    m_treeIssuer->setGeometry(pt.x(), pt.y(), m_treeIssuer->width(),
                              m_treeIssuer->height());
    m_treeIssuer->show();
  }
}

void BestQuoteFilter::showGuarantorFilter(SImageButton* btn) {
  if (!m_treeGuarantor) {
    m_treeGuarantor = new STreeComboWidget(nullptr, false, true, 20, 212);
    m_treeGuarantor->setWindowFlags(m_treeIssuer->windowFlags() |
                                    Qt::FramelessWindowHint);
    m_treeGuarantor->setFixedWidth(248);
    m_treeGuarantor->setFixedHeight(212);
    m_treeGuarantor->setFocusPolicy(Qt::NoFocus);
    m_treeGuarantor->showToolTip(200);
    m_treeGuarantor->setAutoDisappear();

    connect(m_treeGuarantor, &STreeComboWidget::itemSelectChanged, this,
            &BestQuoteFilter::onFilterGuarantorClick);
    connect(m_treeGuarantor, &STreeComboWidget::filterIndexSelectChanged, this,
            &BestQuoteFilter::onFilterGuarantorIndexClick);

    onFilterGuarantorIndexClick(0);
  }

  if (!m_treeGuarantor->isVisible()) {
    QRect rc = btn->rect();
    QPoint pt = btn->mapToGlobal(QPoint(rc.left(), rc.bottom()));
    m_treeGuarantor->setGeometry(pt.x(), pt.y(), m_treeGuarantor->width(),
                                 m_treeGuarantor->height());
    m_treeGuarantor->show();
  }
}

void BestQuoteFilter::enableRateGroup() {
  m_tabBondNCD->enableAllTabs();
  m_treeNCD->setTreeEnable(true);
  m_tabInvest->enableAllTabs();
  m_treeMuniArea->setTreeEnable(true);
  m_tabPformType->enableAllTabs();
  m_tabGrade->enableAllTabs();
  m_tabBank->enableAllTabs();
  m_treeSector->setTreeEnable(true);
  m_tabCorp->enableAllTabs();
  m_tabBondAssure->enableAllTabs();
  m_tabThirdPartGuarantee->enableAllTabs();
  m_searchGuarantor->setSearchEnable(true);
  m_tabIssuerRating->enableAllTabs();
  m_treeIssuerRating->setTreeEnable(true);
  m_tabCBRRating->enableAllTabs();
  m_treeCBRRating->setTreeEnable(true);
  m_tabOutlook->enableAllTabs();
  m_tabBondRating->enableAllTabs();
  m_treeBondRating->setTreeEnable(true);
  m_tabCDCRating->enableAllTabs();
  m_treeCDCRating->setTreeEnable(true);
  m_tabCSIRating->enableAllTabs();
  m_treeCSIRating->setTreeEnable(true);
  m_tabAssetStatus->enableAllTabs();
  m_tabETSBond->enableAllTabs();
  m_tabSubordinatedBond->enableAllTabs();
  m_treeSubType->setTreeEnable(true);

  m_labelGuarantor->setStyleSheet(
      QString("padding-left: 4px;color:#%1; background-color:#%2;border:1px "
              "solid #%2;border-radius:2px")
          .arg(StyleMgr::instance().color("TitleWord").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("StaticTextBK").rgb(), 0, 16));
}

void BestQuoteFilter::disableRateGroup() {
  m_tabBondNCD->disableAllTabs();
  m_treeNCD->clearSelect();
  m_treeNCD->setTreeEnable(false);
  m_tabInvest->disableAllTabs();
  m_treeMuniArea->clearSelect();
  m_treeMuniArea->setTreeEnable(false);
  m_tabPformType->disableAllTabs();
  m_tabGrade->disableAllTabs();
  m_tabBank->disableAllTabs();
  m_treeSector->clearSelect();
  m_treeSector->setTreeEnable(false);
  m_tabCorp->disableAllTabs();
  m_tabBondAssure->disableAllTabs();
  m_tabThirdPartGuarantee->disableAllTabs();
  m_searchGuarantor->setSearchEnable(false);
  m_tabIssuerRating->disableAllTabs();
  m_treeIssuerRating->clearSelect();
  m_treeIssuerRating->setTreeEnable(false);
  m_tabCBRRating->disableAllTabs();
  m_treeCBRRating->clearSelect();
  m_treeCBRRating->setTreeEnable(false);
  m_tabOutlook->disableAllTabs();
  m_tabBondRating->disableAllTabs();
  m_treeBondRating->clearSelect();
  m_treeBondRating->setTreeEnable(false);
  m_tabCDCRating->disableAllTabs();
  m_treeCDCRating->clearSelect();
  m_treeCDCRating->setTreeEnable(false);
  m_tabCSIRating->disableAllTabs();
  m_treeCSIRating->clearSelect();
  m_treeCSIRating->setTreeEnable(false);
  m_tabAssetStatus->disableAllTabs();
  m_tabETSBond->disableAllTabs();
  m_tabSubordinatedBond->disableAllTabs();
  m_treeSubType->clearSelect();
  m_treeSubType->setTreeEnable(false);

  m_labelGuarantor->setStyleSheet(
      QString("padding-left: 4px;color:#%1; background-color:#%2;border:1px "
              "solid #%2;border-radius:2px")
          .arg(StyleMgr::instance().color("TipsBorder").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("StaticTextBK").rgb(), 0, 16));
}

void BestQuoteFilter::enableCreditGroup() {
  m_tabLocalBond->enableAllTabs();
  m_treeLocalBondSpecial->setTreeEnable(true);
  m_tabLocalBondArea->enableAllTabs();
  m_treeLocalBondArea->setTreeEnable(true);
  m_tabBondNCD->enableAllTabs();
  m_treeNCD->setTreeEnable(true);
}

void BestQuoteFilter::disableCreditGroup() {
  m_tabLocalBond->disableAllTabs();
  m_treeLocalBondSpecial->clearSelect();
  m_treeLocalBondSpecial->setTreeEnable(false);
  m_tabLocalBondArea->disableAllTabs();
  m_treeLocalBondArea->clearSelect();
  m_treeLocalBondArea->setTreeEnable(false);
  m_tabBondNCD->disableAllTabs();
  m_treeNCD->clearSelect();
  m_treeNCD->setTreeEnable(false);
}

void BestQuoteFilter::enableNCDGroup() {
  m_tabLocalBond->enableAllTabs();
  m_treeLocalBondSpecial->setTreeEnable(true);
  m_tabLocalBondArea->enableAllTabs();
  m_treeLocalBondArea->setTreeEnable(true);
}

void BestQuoteFilter::disableNCDGroup() {
  m_tabLocalBond->disableAllTabs();
  m_treeLocalBondSpecial->clearSelect();
  m_treeLocalBondSpecial->setTreeEnable(false);
  m_tabLocalBondArea->disableAllTabs();
  m_treeLocalBondArea->clearSelect();
  m_treeLocalBondArea->setTreeEnable(false);
  m_tabBondNCD->enableAllTabs();
  m_treeNCD->setTreeEnable(true);
}
